megengine.random.normal

normal(mean=0, std=1, size=None)

服从高斯分布的随机变量 \(N(\mu, \sigma)\)

参数
  • mean (float) – the mean or expectation of the distribution. Default: 0.

  • std (float) – the standard deviation of the distribution (variance = \(\sigma ^ 2\)). Default: 1.

  • size (Optional[Iterable[int]]) – the size of output tensor. Default: None.

返回

tensor. The random variable with Gaussian distribution.

返回类型

Return type

实际案例

>>> import megengine.random as rand
>>> x = rand.normal(mean=0, std=1, size=(2, 2))
>>> x.numpy()   
array([[ 1.5534291 , -0.28356555],
       [ 2.2230418 , -0.92425716]], dtype=float32)