Hello, I am on the week 3 assignment of the Neural Networks course. In the formulas given for the back-propagation, I am getting error when finding dZ1, that my shapes of the matrices are not aligned( shapes (4,3) and (4,3) not aligned: 3 (dim 1) != 4 (dim 0)).
Also it is not given in the backpropagation function that we have to access Z1 from the cache dictionary and use it. Is there any bug in the formula? I have found that the shapes of g1_prime and Z1 are the same therefore the matrix multiplication cannot take place.
Kindly help, as I am stuck on this problem for the past few days. I have also attached a picture of the formulas given in the notebook
Thank you
Hello @Bakhtiar_Rasheed! I hope you are doing well.
Are you using the right side’s formulas? How you calculating the g1`? See hint:
Furthermore, are you using correct code to retrieve W1 and W2 from the dictionary “parameters” and A1 and A2 from dictionary “cache”?
Best,
Saif.
yes I am calculating g1 prime as (1-np.power(a1,2)). Also I am correctly getting w1,w2,a1,a2 and z1 from the parameters and cache dictionary
And, are you using the right side equations?
Can you share full error, please?
Yes I am using the right side equations

Should I share my complete code?
Kindly double check the dZ1
. You are implementing it incorrectly. Especially second part. Remember that if a=g^{[1]}(z) then g^{[1]} ′(Z^{[1]})=1−a^2 . Double check the below hint:
Oh, g1 is a function, I thought that z1 was being multiplied to 1-a2.
Thank you. It works now