In week 4 assignemtn assertion errors are coming

AssertionError Traceback (most recent call last)
in
1 t_dZ, t_linear_cache = linear_backward_test_case()
----> 2 t_dA_prev, t_dW, t_db = linear_backward(t_dZ, t_linear_cache)
3
4 print("dA_prev: " + str(t_dA_prev))
5 print("dW: " + str(t_dW))

in linear_backward(dZ, cache)
28 assert (dA_prev.shape == A_prev.shape)
29 assert (dW.shape == W.shape)
—> 30 assert (isinstance(db, float))
31
32 return dA_prev, dW, db

AssertionError:

Right, the error here tells you " assert (isinstance(db, float))" this mean that when you calculate db in linear_backward(dZ, cache) function the db is not a float, you could possibly cast it to float or maybe better use in the division like for eg. 5.0/something…

As Gent mentioned, your db type is not as expected. So, the question is, “How did it get that way?” Add the below lines in your code, after defining the db.

print(f'type of db: {type(db)}')
print(f'db: {db}')
    

My output is:

type of db: <class 'numpy.ndarray'>
db: [[-0.14713786]
 [-0.11313155]
 [-0.13209101]]

Check yours and post us here.

Best,
Saif.

I got db values correctly, But now I am getting the following error
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

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

~/work/release/W4A1/public_tests.py in linear_backward_test(target)
308 ]
309
→ 310 multiple_test(test_cases, target)
311
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))
143

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

Notice that your shape of db is not the same as expected. You have to use axis = 1, keepdims = True in np.sum.

I used the same
db = {Moderator Edit: Code Removed}

Why you are squeezing the db?

It was wrong. Thank you
I got it right now.