Please note that we can also use the randn() function to generate random numbers from the normal distribution with a particular mu and sigma. For example, the following piece of Python code will generate 10000 random numbers from the normal distribution that has a mu = 10 and sigma = 2.
from numpy.random import randn mu = 10 sigma = 2 X2 = sigma*randn(10000) + mu
The code will generate 10000 floating point random numbers from the normal distribution that has the mean 10 and standard deviation sigma = 2.
We can verify the same by plotting the distribution of the numbers using a histogram.
from numpy.random import randn from matplotlib import pyplot mu = 10 sigma = 2 X2 = sigma*randn(10000) + mu pyplot.hist(X2, bins=100) pyplot.savefig("randn-2.png") pyplot.close()
The histogram will look like the following:






0 Comments