mercredi 18 décembre 2019

How to generate a random float in range [-1,1] using numpy.random.rand()?

Numpy's random.rand() function produces random floats between 0 and 1. How do I transform the output of this function to produce random floats between -1 and 1?

Current output:

In[]: numpy.random.rand(3, 2)
Out[]: 
array([[0.13568674, 0.72465483],
       [0.48726461, 0.68867378],
       [0.50463821, 0.28619853]])

Desired (example) output:

In[]: numpy.random.rand(3, 2)
Out[]: 
array([[-0.13568674, 0.72465483],
       [-0.48726461, 0.68867378],
       [0.50463821, -0.28619853]])

I would not like to use random.uniform().




Aucun commentaire:

Enregistrer un commentaire