Week 2 error about assertionerror

Gradient at initial w, b (zeros): -0.04747762052631062 -0.007323908939747608
Using X with shape (4, 1)

AssertionError Traceback (most recent call last)
6 print(‘Gradient at initial w, b (zeros):’, tmp_dj_dw, tmp_dj_db)
----> 8 compute_gradient_test(compute_gradient)

~/work/public_tests.py in compute_gradient_test(target)
60 dj_dw, dj_db = target(x, y, initial_w, initial_b)
61 #assert dj_dw.shape == initial_w.shape, f"Wrong shape for dj_dw. {dj_dw} != {initial_w.shape}"
—> 62 assert dj_db == -2, f"Case 1: dj_db is wrong: {dj_db} != -2"
63 assert np.allclose(dj_dw, -10.0), f"Case 1: dj_dw is wrong: {dj_dw} != -10.0"

AssertionError: Case 1: dj_db is wrong: -0.6640625 != -2

can someone please help me with this? i don’t think there’s anything wrong with my code but it didn’t work. thanks in advance, appreciate the help

1 Like

Hello @Wynne_Budhiarti ,

Welcome to the community. Could you share your notebook in a private message?

Hi ,
I too am facing the same issue with this assignment. Can Someone please help why do I get this and how to fix it?

The error seems to indicate that the shape of dj_dw is incorrect. It should be an 1D array with the same length (shape) as w. Given that dj_db is also incorrect, my guess would to check how the dj_dw and dj_db are updated, e.g., is += being used instead of = inside the loop (sum over the sample).

Please also note that an array with shape (4,1) is different from (4, ); the former is a 2D array with 4 rows and 1 column (i.e., a column vector), but the latter is an 1D array of length 4.


How do you fix this error? How can I reach out to a mentor?


Instead of returning the value everytimes, iterating through the samples, you suppose to get the value ​​"dj_dw and dj_db" only once you return the value.

Hi there, I am also facing the same problem.
How to solve the Error?

Hello @Ruhollah, Could you share your notebook in a private message?

I have the same error message with week two assignment and I’ve tried to manipulate the code but all in vain. anyone please assist me, thanks