Assignment 1 - Gradient Function error : only size-1 arrays can be converted to Python scalars

In Assignment 1, for the following Gradient function, the test fails.

(Solution code removed by staff as posting it is against the honour code this community)

When the test is run I get the following error message :

     36     ### END CODE HERE ###
---> 37     J = np.float(J)
     38     return J, theta

TypeError: only size-1 arrays can be converted to Python scalars

Checking the shape of J, i see that its (1,10) in each iteration. Is that the issue?

Please check your implementation of sigmoid.
z and h should have the same shape.

1 Like

I am getting the same error for J. I checked the shape of z and h, and those are the same. The code I wrote for J is [code removed - moderator]. Is my code wrong?

@CaoCao Your code for updating J is correct.

Please check the following:

  1. z.shape == h.shape == y.shape == (10, 1)
  2. theta is updated correctly.

If you are still running into issues, please click my name and message your notebook as an attachment.

Oh, I found my mistake, I calculated the sigmoid of x instead of z, and now it works! Thank you!