W3_Ex-6_AssertionError_Wrong values for dW1

I am able to get db2 and dW2 correct. dW1 and db1 are incorrect, perhaps due to incorrect value of dZ1. I used (1 - np.power(A1, 2)) as guided. However, I am unable to get correct value. Please guide.

Are you sure you implement the full formula of dZ1? You just mentioned the second part but there is also W2 and dZ2, right?

Yes, I implemented. I used np.dot to multiply W2 and dZ2.

Send me your code in a private message. Click my name and message.

Check the formula of dZ1 again. W2 or dW2?

Thanks for the help. I really got confused. The issue is solved.

@saifkhanengr , Excuse me, I have a similar problem.

I computed dZ1 this way: dZ1 = np.dot(np.dot(W2.T, dZ2), (1 - np.dot(A1.T, A1)))

Cause using (1 - np.power(A1, 2)) gives an error of shapes: “(4,3) (4,3) not aligned”

Despite I wrote the suggested formula it gives me “AssertionError: Wrong values for dW1”…How can I resolve?

This is incorrect. The * operator implies the element-wise multiplication. So, using dot is incorrect. Also, np.power should not give any error once you use * operator.

It works. If I can ask you, how many years are needed to learn all these kind of ‘python secrets’? (I’m new to this programming language.)

It’s more a matter of understanding how matrix algebra works, not python specifically.

When the equation says to compute the sum of the product of two vectors, you can use a dot product, or you can use sum() and an element-wise multiplication. They’ll give exactly the same results.

But when the implementation involves matrices instead of vectors, then a matrix dot product will produce results that involve all of the products of the off-axis elements of both matrices. This may or may not be what the equation is trying to calculate, depending on the exact situation.

The essential difference is that if the end result is a scalar (such as the cost value), then a dot product may not be the correct choice.

1 Like