0

I have this error:

"TypeError: 'float' object is not subscriptable"

This is the part of the code that displays the error:

nd_coord = random.uniform(npoints, 2)         
nd_coord[:,0] = nd_coord[:,0] * ((xmax - xmin) + xmin)   
nd_coord[:,1] = nd_coord[:,1] * ((ymax - ymin) + ymin)  
print (nd_coord)
1
  • Have you printed nd_coord, or checked it's type and/or shape? Clearly it isn't the 2d array that you expect. Commented May 9, 2015 at 2:53

1 Answer 1

1

I take it you've imported NumPy as from numpy import * and so random.uniform is the NumPy method. Its call signature is:

numpy.random.uniform(low=0.0, high=1.0, size=None)

So the way you're using it, it returns a single number (which can't be indexed). Perhaps you want:

nd_coord = np.random.uniform(size=(npoints,2))

To pick npoints pairs of random numbers on [0,1).

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

Comments

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.