mindspore.ops.normal

View Source On Gitee
mindspore.ops.normal(shape, mean, stddev, seed=None)[source]

Generates random numbers according to the Normal (or Gaussian) random number distribution.

Warning

The Ascend backend does not support the reproducibility of random numbers, so the seed parameter has no effect.

Parameters
  • shape (tuple) – The shape of random tensor to be generated. The format is \((N,*)\) where \(*\) means, any number of additional dimensions.

  • mean (Union[Tensor, int, float]) – The mean μ distribution parameter, which specifies the location of the peak.

  • stddev (Union[Tensor, int, float]) – The deviation σ distribution parameter. It should be greater than 0.

  • seed (int) – Seed is used as entropy source for the Random number engines to generate pseudo-random numbers. The value must be non-negative. Default: None , which will be treated as 0.

Returns

Tensor. The shape should be equal to the broadcasted shape between the input shape and shapes of mean and stddev. The dtype is [float32, float64].

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> shape = (3, 1, 2)
>>> mean = Tensor(np.array([[3, 4], [5, 6]]), mindspore.float32)
>>> stddev = Tensor(1.0, mindspore.float32)
>>> output = ops.normal(shape, mean, stddev, seed=5)
>>> result = output.shape
>>> print(result)
(3, 2, 2)
>>> shape = (3, 1, 3)
>>> mean = Tensor(np.array([[3, 4, 3], [3, 5, 6]]), mindspore.float32)
>>> stddev = Tensor(1.0, mindspore.float32)
>>> output = ops.normal(shape, mean, stddev, seed=5)
>>> result = output.shape
>>> print(result)
(3, 2, 3)
>>> shape = (3, 1, 3)
>>> mean = Tensor(np.array([[1, 2, 3], [3, 4, 3], [3, 5, 6]]), mindspore.float32)
>>> stddev = Tensor(1.0, mindspore.float32)
>>> output = ops.normal(shape, mean, stddev, seed=5)
>>> result = output.shape
>>> print(result)
(3, 3, 3)