W3_A1_backpropagation function_passing wrong parameters

In the backpropagation function
firstly we calculate
dZ[2]= A[2] - Y
A[2] dimensions is (1, 3)
Y dimensions is (1, 400)
Thus I cannot make the subtraction broadcasting, shall I take the transpose of A[2]?
Will this affect the next calculations?

Hi @Fatma_Shaban

A2 should be extracted from the input argument ‘cache’ which is passed to this function together with parameter, X and Y. You can put a print statement to print out the shape of these arguments, that would give some idea where your problem might be.

Thanks for your reply,
Yes, I have done that and used the A2 from the “cache” function, and print the shapes of A2 and Y. Thus I was asking to transpose A[2]. so broadcasting A2.T with Y occurs.

Hi @Fatma_Shaban

Transpose is not going to help, because there is problem with the arguments you are using. If your backward_propagation() has passed the unit test, then the problem is from somewhere else. To make sure your code is running in a correct environment, try:
kernel → restart and clear all output
run all the cell from start to backward_propagation() and make sure the function passes the unit test.

Note that 1 x 400 is the dimension of the real Y value from the actual data we use in this exercise. But in the test cases, they use smaller data for ease of debugging. So what this means is that you must be accidentally referencing global variables instead of the parameters that are actually passed for this test case.

In these courses it is always a mistake to reference global variables from the local scope of your functions: instead reference the parameter values in the function statement.