jeudi 24 septembre 2015

Is there a numpy shortcut for generating array of floats within a desired limit?

If I need an array containing 5 rows of 2 floating point numbers whose values are between 0 and 100, I would normally do this:

coordinates = 100 * np.random.rand(10, 2)

It would produce something similar to the following output:

array([[ 18.12298022,  23.06041984],
       [ 79.29855044,  25.41550915],
       [ 79.61747255,  35.09879784],
       [ 63.75090875,  95.88711405],
       [ 23.87727443,  97.02211991]])

This computation requires generating the random sequence irst and then multiplying it with the desired upper limit (100). Is there a builtin function in numpy's random library that can do this (presumably faster)? I couldn't find one from the docs.




Aucun commentaire:

Enregistrer un commentaire