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

返回

输出张量

实际案例

import megengine as mge
import megengine.random as rand

x = rand.normal(mean=0, std=1, size=(2, 2))
print(x.numpy())

输出:

[[-1.4010863  -0.9874344 ]
 [ 0.56373274  0.79656655]]