mindspore.ops.normal
- mindspore.ops.normal(shape, mean, stddev, seed=None)[source]
Return a random tensor that conforms to the normal (Gaussian) 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 returned tensor.
mean (Union[Tensor, int, float]) – The mean of the normal distribution for the returned tensor.
stddev (Union[Tensor, int, float]) – The standard deviation of the normal distribution for the returned tensor.
seed (int, optional) – Random seed. Default:
None
, which is equivalent to 0.
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> shape = (3, 1, 2) >>> mean = mindspore.tensor([[3, 4], [5, 6]], mindspore.float32) >>> stddev = mindspore.tensor(1.0, mindspore.float32) >>> output = mindspore.ops.normal(shape, mean, stddev, seed=5) >>> result = output.shape >>> print(result) (3, 2, 2) >>> shape = (3, 1, 3) >>> mean = mindspore.tensor([[3, 4, 3], [3, 5, 6]], mindspore.float32) >>> stddev = mindspore.tensor(1.0, mindspore.float32) >>> output = mindspore.ops.normal(shape, mean, stddev, seed=5) >>> result = output.shape >>> print(result) (3, 2, 3) >>> shape = (3, 1, 3) >>> mean = mindspore.tensor([[1, 2, 3], [3, 4, 3], [3, 5, 6]], mindspore.float32) >>> stddev = mindspore.tensor(1.0, mindspore.float32) >>> output = mindspore.ops.normal(shape, mean, stddev, seed=5) >>> result = output.shape >>> print(result) (3, 3, 3)