0

I can't figure out what's preventing me from getting a contour plot of this cost function. After much trial and error, I'm getting:

ValueError: zero-size array to reduction operation minimum which has no identity

If I print J it doesn't give me any values, just a 100x100 array full of nan. Is that the reason? J should be full of cost values, right? Thanks so much for any help.

X,y,ComputeCost = defined earlier and 90% sure not the problem
theta_zero = np.linspace(-10,10,100)
theta_one = np.linspace(-1,4,100)
L,Q = np.meshgrid(theta_zero,theta_one)
J = np.zeros((len(theta_zero),len(theta_one)))

for i in range(0,len(theta_zero)):
    for j in range(0,len(theta_one)):
        t = DataFrame([theta_zero[i],theta_one[j]])
        J[i,j] = ComputeCost(X,y,t)

plt.contour(L,Q,J)

1 Answer 1

1

If J is just nans, then the problem is in the way you're generating J and not the contour() call.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I guess the next question is why are the for loops leaving me with a J full of nan's? As is, the code spits out all the values--one per line--before giving me the error when trying to plot the contour. Not sure why they aren't being stored in J.
So, if you use an intermediate variable it comes out at non-nan? i.e.: foo = ComputeCost(X,y,t) print foo J[i,j] = foo If foo prints out as non-non, then I'm at a loss too.
If I create some other variable, Z, and set it equal to a 100X100 array, then I get the same error with Z[i,j] in the loop as I do with J[i,j].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.