There is always a confusion as to why we have two functions of randn and normal for giving the same output. And the key to understanding the difference between them is to understand, what is a normal and standard normal distribution.
Normal Distribution :
It is a Gaussian distribution or a bell shaped curve which has values distributed around a central value (i.e. the mean) with some standard deviation(i.e. the spread of the distribution).
Definition in python is as below :
numpy.random.normal(loc=0.0, scale=1.0, size=100)
This draws a random sample from the normal Gaussian distribution of dimensions 1x100 centered i.e. a GENERIC normal distribution
loc :- the central value around which values are located
scale :- the standard deviation of the sample
size :- the dimensions of the array returned
Standard Normal Distribution :
It is a distribution or a bell shaped curve which has values distributed around 0 with a standard deviation of 1.
Definition in python is as below :
numpy.random.randn(100)
This draws a random sample from the standard normal distribution of dimensions 1X100 i.e. a SPECIFIC normal distribution
Now here, the values are located around 0 with standard deviation 1.
In the code lines used above, you will find no difference between the outputs as by default normal has mean 0 and standard deviation 1 i.e. same as the standard normal distribution.
Now try playing around with the loc and scale in normal.
You can use the below lines and see the difference.
Below is a simple trick through which you achieve the same functionality of normal using randn only.
2 * numpy.random.randn(100) + 10
1 * numpy.random.randn(100) + (-5)
Both the methods produce the same output. Still it's good to know different ways of doing same thing.
Also don't confuse the above functions with
numpy.random.rand(100)
Now I leave this final part for you to explore yourself.
This is it for today.
Comments
Post a Comment