Help Week 4 assignment 1 Exercise 7


I keep getting this error message and I am not sure what I am doing wrong

Here is the correct output from that test cell (which of course they also show you in the notebook):

dA_prev: [[-1.15171336  0.06718465 -0.3204696   2.09812712]
 [ 0.60345879 -3.72508701  5.81700741 -3.84326836]
 [-0.4319552  -1.30987417  1.72354705  0.05070578]
 [-0.38981415  0.60811244 -1.25938424  1.47191593]
 [-2.52214926  2.67882552 -0.67947465  1.48119548]]
dW: [[ 0.07313866 -0.0976715  -0.87585828  0.73763362  0.00785716]
 [ 0.85508818  0.37530413 -0.59912655  0.71278189 -0.58931808]
 [ 0.97913304 -0.24376494 -0.08839671  0.55151192 -0.10290907]]
db: [[-0.14713786]
 [-0.11313155]
 [-0.13209101]]
 All tests passed.

Notice that your db value is different than what I showed above. The values are the same, but the shape is different. Notice that yours has only one set of brackets, which means that it’s a 1 dimensional array. What I show for db has two dimensions: it’s a 3 x 1 column vector. So the first thing to check is whether you omitted the keepdims argument on the np.sum call that you used in computing db. They mentioned that in the comments and it turns out to matter. And notice that the error you get is complaining about the shape of one of your outputs. You’d have to look at the test code to make sure that it’s db that it’s talking about. But notice that the shapes and values of your dA_prev and dW values agree with what I showed.

You can confirm my theory by adding this print statement to your code after you compute db:

print(f"db.shape {db.shape}")

I predict that what you get will be (3,), which means it is a 1D object with 3 elements. When I do that, I get:

db.shape (3, 1)