Z1 is 4x3 and G’ is 4x3. Now if we do dot product we will get either 4x4 or 3x3 matrix
But W[2]T . dZ[2] are resulting 4x3 So, element wise multiplication not possible. Kindly tell where I am wrong.
dZ[2], dW[2], db[2] are correct.
dW[1] is wrong.

Below is code snippet:

{moderator edit - solution code removed}

The output is:

db2 dim (1, 1)
A1 (4, 3)
W2 Shape (1, 4)
W1 Shape (4, 2)
dZ2 Shape (1, 3)
Z1 (4, 3)
X (2, 3)
m is 3
So far dZ1 (4, 3)
2nd part dim (3, 3)
g’ shape (4, 3)

It looks like you are talking about the back propagation function in Week 3 Planar Data Assignment, right? It helps if you can specify which problem you are working on.

Why are you transposing the output of g^{[1]'}(Z1)? That is not specified in any of the formulas, right?

Z1 is 4 x 3 so g(Z1) will also be 4 x 3, right? The activations are always “elementwise”.

You are misinterpeting the dZ1 formula. You don’t need to multiply by Z1, right? You are invoking the function g'(Z1). It just turns out that for tanh that happens to be:

g'(Z1) = 1 - tanh^2(Z1)

Which can also be expressed as (1 - A1^2), because:

@Rashmi: I think the elementwise multiplies are actually there but Suhas did not use the </> tool to format the code “as is”. If you don’t do that then the * gets interpreted as markdown and ends up italicizing things. You can see that the np.power call is italicized there.