Week4 excercise 7

I am getting this error while implementing linear backward

AssertionError Traceback (most recent call last)
6 print("db: " + str(t_db))
----> 8 linear_backward_test(linear_backward)

~/work/release/W4A1/public_tests.py in linear_backward_test(target)
308 ]
→ 310 multiple_test(test_cases, target)
312 def linear_activation_backward_test(target):

~/work/release/W4A1/test_utils.py in multiple_test(test_cases, target)
140 print(’\033[92m’, success," Tests passed")
141 print(’\033[91m’, len(test_cases) - success, " Tests failed")
→ 142 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for linear_backward. Check your equations and avoid using global variables inside the function.


{moderator edit - solution code removed}

Thank you…

What is the purpose of using both keepdims = True and then np.squeeze on the result? The squeeze will defeat the purpose of the keepdims, right? Check the shape of your db. It should be the same shape as b, but I will predict it comes out to be a 1D array not a 2D array.

Also just as a programming style point, they already gave you the code to extract the elements of the cache parameter in the template code. Your code will be clearer if you use those variables rather than indexing cache as you do.

Thank you sir, Now it solved.

Just for future reference, the error message did tell you that your db was the wrong shape. I tried making your “squeeze” mistake and here is the earlier part of the error trace that I got:

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]
Error: Wrong shape for variable 2.
Error: Wrong output for variable 2.
 1  Tests passed
 2  Tests failed

You can see in that output that db is a 1D array. Note the brackets: only one set. That’s a bad sign. :scream_cat:

There are some cases where the test cases and the grader don’t give very specific feedback, but this is not one of them. :nerd_face: