Course 1 Week 4 Assignment 1

Hi, am unsure why am i receiving this error

For dot product, the matrices A and B are compatible if number of columns in first match the number of rows in second, i.e. if A is p X q and B is q X r. Since both of your matrices are 3 X 4, the dot product condition is not satisfied.
Can you think of a method that will align them for dot product?

My recommendation for debugging a problem like this is to start with the “dimensional analysis”: write down the dimensions of all the input values and then figure out what should happen at each layer during the forward propagation. Here’s what we have:

X is 5 x 4
W1 is 4 x 5 and b1 is 4 x 1
W2 is 3 x 4 and b2 is 3 x 1
W3 is 1 x 3 and b3 is 1 x 1

So at layer one, the “linear” calculation is:

Z1 = W1 dot X + b1

So that dot product is 4 x 5 dot 5 x 4, which gives a 4 x 4 result. Since the activation function is “elementwise” it doesn’t change the dimensions. So we have Z1 and A1 are 4 x 4.

At layer 2, we have:

Z2 = W2 dot A1 + b2

So that is 3 x 4 dot 4 x 4 which gives 3 x 4 output. So Z2 and A2 are 3 x 4.

At layer 3 we have:

Z3 = W3 dot A2 + b3

So we have 1 x 3 dot 3 x 4 gives 1 x 4 output. So Z3 and A3 should be 1 x 4.

So what is happening in your case? How could you end up with 3 x 4 dot 3 x 4 (which as vj has pointed out does not work)?

I think the bug is that your logic is wrong for the layer 3 case after you fall out of the “for” loop. The question is what is the value of “l” (ell) in that case? I think that is causing you to select the wrong W value for layer 3.


managed to solve it, if i’m not mistaken i should be using L instead of l for linear to sigmoid. At least from the picture :confused:

1 Like