numpy.random.standard_normal

random.standard_normal(size=None)

从标准正态分布(平均值=0,标准偏差=1)中提取样本。

注解

新代码应该使用 standard_normal A方法 default_rng() 请参阅 快速启动 .

参数
sizeint或int的元组,可选

输出形状。如果给定的形状是,例如, (m, n, k) 然后 m * n * k 取样。默认值为无,在这种情况下返回单个值。

返回
out浮动还是日积月累

形状的浮点数组 size 或单个样品,如果 size 未指定。

参见

normal

带附加项的等价函数 locscale 设定平均值和标准差的论据。

Generator.standard_normal

应该用于新代码。

笔记

对于随机样本 N(\mu, \sigma^2) ,使用以下选项之一:

mu + sigma * np.random.standard_normal(size=...)
np.random.normal(mu, sigma, size=...)

实例

>>> np.random.standard_normal()
2.1923875335537315 #random
>>> s = np.random.standard_normal(8000)
>>> s
array([ 0.6888893 ,  0.78096262, -0.89086505, ...,  0.49876311,  # random
       -0.38672696, -0.4685006 ])                                # random
>>> s.shape
(8000,)
>>> s = np.random.standard_normal(size=(3, 4, 2))
>>> s.shape
(3, 4, 2)

来自 N(3, 6.25)

>>> 3 + 2.5 * np.random.standard_normal(size=(2, 4))
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],   # random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]])  # random