我是一个统计学家,有时会编代码,反之亦然,所以这是我能准确回答的问题。
查看您在问题中链接的文档,我将重点介绍一些关键区别:
正常:numpy.random.normal(loc=0.0, scale=1.0, size=None)
# Draw random samples from a normal (Gaussian) distribution.
# Parameters :
# loc : float -- Mean (“centre”) of the distribution.
# scale : float -- Standard deviation (spread or “width”) of the distribution.
# size : tuple of ints -- Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn.
因此,在本例中,您将生成一个一般正态分布(稍后将详细说明这意味着什么)。
兰登:numpy.random.randn(d0, d1, ..., dn)
# Return a sample (or samples) from the “standard normal” distribution.
# Parameters :
# d0, d1, ..., dn : int, optional -- The dimensions of the returned array, should be all positive. If no argument is given a single Python float is returned.
# Returns :
# Z : ndarray or float -- A (d0, d1, ..., dn)-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied.
在本例中,您将生成一个特定的正态分布,即标准分布。
现在,一些数学,这是真正需要得到的核心问题:
正态分布是指值在均值附近出现的可能性更大的分布。自然界中有很多这样的情况。E、 例如,达拉斯6月份的平均高温是95华氏度,一年内可能达到100华氏度,甚至105华氏度,但更典型的是接近95或97华氏度。同样,它可能会低至80,但85或90更有可能。
因此,它与均匀分布(滚动一个诚实的6边模具)有根本的不同。
A标准正态分布只是平均值为0,方差(变量的数学术语)为1的正态分布。
所以numpy.random.normal(size= (10, 10))
和写作完全一样numpy.random.randn(10, 10)
因为numpy.random.normal的默认值(loc=0,scale=1)实际上是标准分布。sigma * np.random.randn(...) + mu
与np.random.normal(loc= mu, scale= sigma, ...)
*最后一点:我用方差这个词来数学描述方差。有些人说标准差。方差等于标准差的平方。由于标准分布的方差为1,在本例中为标准分布,variance == standard deviation。