mindspore.mint.normal

View Source On AtomGit
mindspore.mint.normal(mean, std, *, generator=None) Tensor[source]

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

Parameters:
  • mean (Union[Tensor]) – Mean value of each element, the shape of the mean tensor should be the same as that of the std tensor.

  • std (Union[Tensor]) – Standard deviation for each element, the shape of the std tensor should be the same as that of the mean tensor. The value of std should be greater than or equal to 0.

Keyword Arguments:

generator (generator, optional) – MindSpore generator. Default: None.

Returns:

Outputs a tensor with the same shape as mean.

Raises:

TypeError – If mean or std is not Union[float, Tensor].

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import mint
>>> from mindspore import Tensor
>>> mean = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32)
>>> std = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32)
>>> output = mint.normal(mean, std)
>>> print(output.shape)
(3,)
mindspore.mint.normal(mean, std) Tensor[source]

Similar to the function above, but the means are shared among all drawn elements.

Parameters:
  • mean (float) – Mean value of each element.

  • std (Tensor) – Standard deviation for each element. The value of std should be greater than or equal to 0.

Returns:

Outputs a tensor with the same shape as std.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import mint
>>> from mindspore import Tensor
>>> mean = 1.
>>> std = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32)
>>> output = mint.normal(mean, std)
>>> print(output.shape)
(3,)
mindspore.mint.normal(mean, std=1.0) Tensor[source]

Similar to the function above, but the standard deviations are shared among all drawn elements.

Parameters:
  • mean (Tensor) – Mean value of each element.

  • std (float, optional) – Standard deviation for each element. The value of std should be greater than or equal to 0. Default: 1.0.

Returns:

Outputs a tensor with the same shape as mean.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import mint
>>> from mindspore import Tensor
>>> mean = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32)
>>> output = mint.normal(mean, 1.0)
>>> print(output.shape)
(3,)
mindspore.mint.normal(mean, std, size) Tensor[source]

Similar to the function above, but the means and standard deviations are shared among all drawn elements. The result tensor has size given by size.

Parameters:
  • mean (float) – Mean value of each element.

  • std (float) – Standard deviation for each element.

  • size (tuple) – output shape.

Returns:

Outputs a tensor. The shape is specified as size.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import mint
>>> from mindspore import Tensor
>>> output = mint.normal(1.0, 2.0, (2, 4))
>>> print(output.shape)
(2, 4)