In Python, we can use the randn() function to generate random numbers from the normal distribution. We need to import the corresponding module in the following way:
from numpy.random import randn
After importing the numpy.random module, we can use the randn() function in the following way:
X1 = randn(10000)
Here, the randn() function will return 10000 floating point random numbers from the standard normal distribution. Therefore, the mean of the generated numbers will be 0, and the standard deviation will be 1.
After generating 10000 such random numbers from the standard normal distribution, we can plot the distribution using a histogram.
pyplot.hist(X1, bins=100) pyplot.savefig("randn-1.png") pyplot.close()
The histogram will look like the following:






0 Comments