Error in the C2_W1_Assignment

Hello i got an error in the last code block of this assignment, i attached an image of the error

The error is in the shape of the errors array, you have to check its shape and especially at the cell where you are producing it so you can fix the mis-shape.

Sir , i am not producing anything, i didn’t write this code , it was there when i reached it and i was supposed to just run it to see a misclassified image

But the errors matrix is coming from y and Yhat, you have to trace why that errors matrix produced from np.where involving y and yhat are not giving you the right shapes.

Actually if you traceback the codes, you will see

Prediction = my_sequential_v(X, W1_tmp, b1_tmp, W2_tmp, b2_tmp, W3_tmp, b3_tmp )

Yhat = (Prediction >= 0.5).numpy().astype(int)

So you can inspect the Yhat and the Prediction and work backwards. There might be some mistake that is there in one of the earlier functions you defined.
So cross-checking everything would help.

thank you hsuyab and gent.spah for the replies , i spend nearly an hour trying to find the error but to no avail , but i re-ran the whole assignment again with the same code with zero change and it worked !!!

1 Like

Yeah sometimes it is a good idea to restart kernel and run the code since there might be some old variables/function that is causing the error.

1 Like

I suspect that during your debugging session, you ran a cell out-of-sequence and it scrambled some of the variables.

Any time you do any editing, it’s a good practice to run all of the cells starting from the top of the notebook.

1 Like

The C2_W1 assignment has this code

Yhat = (Prediction >= 0.5)astype(int)
when it should be
Yhat = (Prediction >= 0.5).numpy().astype(int)

Once I added the .numpy(), it worked.

No, that’s not necessary.

Perhaps there is some other error in your code, which adding “.numpy” is fixing.