Error in exercise 5 week 2

Hello Team,

I am getting wrong data type for db(backward propagation) as in attached document. Can I know what can be wrong here?

(code removed)

Below is my code:

(code removed)

Error
Quote:

AssertionError Traceback (most recent call last)
in
7 assert type(grads[“dw”]) == np.ndarray
8 assert grads[“dw”].shape == (2, 1)
----> 9 assert type(grads[“db”]) == np.float64
10
11

AssertionError:

Unquote:

Thanks in advance

Hi @nandita_singh, you can read from the assertion error that db is expected to be a scalar, a float. It currently is not. if you look at your calculations, both dw and db are using np.dot so are returning an array. So indeed, you need something different then np.dot for the calculation of db. What would that be?

Note that it is policy not to share code solutions on our platform so I removed them.

2 Likes

Thanks for clarification but I am still lost how to get a scalar quantity for db.

Hi @nandita_singh, have a look at equation (8) in the hints section, you have to use a np.sum, not a np.product

That’s such a silly one. I am so sorry to be a stupid one. In my head I was calculating L2 loss.Thanks for being kind to my attention while it was actually lying there in the plain sight all along.

Great @nandita_singh, and rest assured, there are no such things as silly mistakes. When coding with matrices, and matrix operations, you sometimes can look for hours for a tiny error that you overlook, at least I do as well… :grinning: Good to see that you fixed it, enjoy the rest of the course!

1 Like

Thanks a bunch. but now i am getting this error :frowning:

Hi @nandita_singh, are you sure that you ran the cells using shift+enter key? Because the shared traceback looks fine. Thanks!

Yes I did. Exercise 8 gave me above errors but later calculated cost after iterations all fine. But when i go ahead and run “plot running curve with costs” , I get attached error.

I am definitely missing on something just don’t know what exactly.

Hi @nandita_singh could you send me your code in a direct message. Then I will try to check.

Message sent with code for model function.

I do get the cost iterations but rest of functions after the exercise don’t run