C1, Week 2, Exercise 6 : Assertion Error with costs variable

Hi all, I am new and got these error in exercise 6 of week 2.
Exercise 6 Error: Here, although the values are same, the costs variable is printed as arrays. I have not hardcoded any value and as per my understanding I did everything correct. Please help.

Hi @Digma_Sharma, and welcome to the Specialization.

It looks like there is something up with your cost function in propogate. The cost should be a scalar, not a two-dimensional list. The odd thing is, is that the first array (a scalar in this case) in the list gives the correct evaluation of the cost. Good news! you seem to be on the right track. The mystery is an additional cost term. :thinking: Study your expression for cost very carefully using the preamble to Exercise 5 as your guide. Pay attention to the dimensions of A, which you defined in the previous line.

Greetings Sir, I’ve been facing the same assertion error. I rewrote the propagate function (Exercise 5) and it is running without any error. I couldn’t solve the error.

Hi, @Lokesh21, in the above comment @kenb sir has already explained the cause. You are not using the propagate function to calculate the cost and gradient for the current parameters. Please go through the equation once and rectify it accordingly. Thanks!

Hello, @Rashmi mam, I’ve called the propagate function and passed the required parameters to calculate the gradient and the cost. The error is caused by the optimize_test(optimize) function and couldn’t resolve.

You are passing the right code as per the shared screenshot. Probably, you might have hardcoded the values somewhere. Doing the copy/paste thing will never give you the desired result. Look for it.

If that’s not the case, then go to the kernel, click restart and clear output. Then, save your work and run all the cells from the beginning through shift+enter key.

Note: I am just a learner like you right now. Please dont refer me as Ma’am.


@Rashmi, I’ve resolved the issue, I made mistake in calculating the parameter w, b in the optimize function.

1 Like

That’s great to learn that!