John Smith
John Smith

Reputation: 1099

how can i create a random array of floats from 0 to 1

I want to create a random float array of size 100, with the values in the array ranging from 0 to 1. I have tried random.sample(range(1),100) but that does not work. How can i get what i want to achieve?

Upvotes: 0

Views: 256

Answers (2)

Warren Weckesser
Warren Weckesser

Reputation: 114811

If you will be doing a lot of array computations, consider using the numpy library (http://www.numpy.org/). With numpy, you can use the function numpy.random.random:

>>> a = numpy.random.random(100)

Upvotes: 1

Pavel Anossov
Pavel Anossov

Reputation: 62908

[random.random() for _ in range(100)]

Upvotes: 4

Related Questions