megengine.random package

megengine.random.distribution

megengine.random.distribution.normal(mean=0, std=1, size=None)[source]

Random variable with Gaussian distribution \(N(\mu, \sigma)\).

Parameters
  • size (Optional[Iterable[int]]) – output tensor size.

  • mean (float) – the mean or expectation of the distribution.

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

Return type

Tensor

Returns

the output tensor.

Examples:

import megengine as mge
import megengine.random as rand

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

Outputs:

[[-0.20235455 -0.6959438 ]
 [-1.4939808  -1.5824696 ]]
megengine.random.distribution.uniform(low=0, high=1, size=None)[source]

Random variable with uniform distribution $U(0, 1)$.

Parameters
  • size (Optional[Iterable[int]]) – output tensor size.

  • low (float) – lower range.

  • high (float) – upper range.

Return type

Tensor

Returns

the output tensor.

Examples:

import megengine as mge
import megengine.random as rand

x = rand.uniform(size=(2, 2))
print(x.numpy())

Outputs:

[[0.76901674 0.70496535]
 [0.09365904 0.62957656]]

megengine.random.rng

megengine.random.rng.seed(seed)[source]