How can i create a random array of floats from 0 to 5 in python

llanitedave llanitedave at veawb.coop
Tue Mar 12 21:21:16 CET 2013


On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote:
> On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:
> 
> > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve?
> 
> 
> 
> Use numpy
> 
> 
> 
> import numpy as np
> 
> np.random.uniform(0, 5, 100)
> 
> 
> 
> # note that the values are from the interval [0, 5)
> 
> 
> 
> Maarten

While numpy would work, I fail to see how encouraging the op to download and install a separate library and learn a whole new set of tools would be beneficial by default, without knowing the purpose of the need.  This is like recommending an RPG to fix a sticky door hinge.



More information about the Python-list mailing list