Home > Article > Backend Development > Detailed explanation of the difference between numpy.random.randn() and rand()
The following is a detailed explanation of the difference between numpy.random.randn() and rand(). It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together
numpy There are some commonly used functions used to generate random numbers, randn() and rand() belong to them.
numpy.random.randn(d0, d1, …, dn) returns one or more sample values from the standard normal distribution.
numpy.random.rand(d0, d1, …, dn) ’s random sample is located in [0, 1).
import numpy as np arr1 = np.random.randn(2,4) print(arr1) print('******************************************************************') arr2 = np.random.rand(2,4) print(arr2)
Result:
[[-1.03021018 0.5197033 0.52117459 -0.70102661] [ 0.98268569 1.21940697 -1.095241 -0.38161758]] ****************************************************************** [[ 0.19947349 0.05282713 0.56704222 0.45479972] [ 0.28827103 0.1643551 0.30486786 0.56386943]]
The above is the detailed content of Detailed explanation of the difference between numpy.random.randn() and rand(). For more information, please follow other related articles on the PHP Chinese website!