mindspore.ops.standard_normal

mindspore.ops.standard_normal(shape, seed=0, seed2=0)[source]

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

Returns the tensor with the given shape, the random numbers in it drawn from normal distributions whose mean is 0 and standard deviation is 1.

\[f(x)=\frac{1}{\sqrt{2 \pi}} e^{\left(-\frac{x^{2}}{2}\right)}\]
Parameters
  • shape (Union[tuple, Tensor]) – The shape of random tensor to be generated. Only constant value is allowed when the input type is tuple. And the operator supports dynamic shape only when the input type is Tensor.

  • seed (int) – Random seed, must be non-negative. Default: 0.

  • seed2 (int) – Random seed2, must be non-negative. A second seed to avoid seed collision. Default: 0.

Returns

Tensor. The shape that the input ‘shape’ denotes. The dtype is float32.

Raises
  • TypeError – If seed or seed2 is not an int.

  • TypeError – If shape is neither a tuple nor a Tensor.

  • ValueError – If seed or seed2 is not a non-negative int.

  • ValueError – If shape is a tuple containing non-positive items.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import ops
>>> shape = (4, 4)
>>> output = ops.standard_normal(shape)
>>> result = output.shape
>>> print(result)
(4, 4)