C1_W3 assignment ---> compute_gradient test error

When I try to test compute_gradient function I get this error. What could be the reason ?

It seems the problem is with dj_db. It should be a scalar (single value) but I think yours is an array. Try printing out the value of it, outside the loop.

print(f"dj_db: {dj_db}")

I have a similar Assertion problem:

Any ideas for what is wrong here?

Diyar, did print(f"dj_db: {dj_db}") work for you? I still don’t understand it.

Your code is not calculating dj_db correctly.

I solved it, the reason is I was returning dj_dw, dj_db. Instead I returned dj_db, dj_dw.

Thank you. My return the term has dj_db before dj_dw , but now I am getting “NameError: name ‘np’ is not defined” pointing to a problem with line 2 initial_w = np.zeros(n).

You have to run all the above cells every time you open your assignment, reload, or restart the kernel.

Yes, that was part of the problem. The other was an over-indentation problem towards the end of my code. It’s solved now. Thank you!