Python difference between randn and normal

前端 未结 3 893
情深已故
情深已故 2021-01-31 15:29

I\'m using the randn and normal functions from Python\'s numpy.random module. The functions are pretty similar from what I\'ve read in the

3条回答
  •  走了就别回头了
    2021-01-31 16:29

    Following up to @Mike Williamson's explanation about variance, standard deviation, I was caught trying to workout the example provided in the Numpy documentation for randn The example provided there:

    >>> import numpy as np
    >>> 2.5 * np.random.randn(2, 4) + 3
    array([[-1.13788245,  2.54061141, -0.12769502,  7.46200906],
           [-0.4780766 ,  1.70417835,  5.43802441,  4.71764135]])
    

    The point to note here is that Normal Distribution follows notation N(Mean, Variance), whereas to implement using .randn() you would require to multiply the standard deviation or sigma and add the Mean or mu to the Standard Normal Output of the Numpy method(s).

    Note:

    sqrt(Variance) = Standard Deviation or sigma

    Eg.,

    sqrt(6.25) = 2.5

    Hence:

    sigma * numpy.random.randn(2, 4) + mean

提交回复
热议问题