mindspore.ops.normal
- mindspore.ops.normal(shape, mean, stddev, seed=None)[源代码]
根据正态(高斯)随机数分布生成随机数。
- 参数:
shape (tuple) - Tuple: \((N,*)\) ,其中 \(*\) 表示任何数量的附加维度。
mean (Tensor) - 均值μ,指定分布的峰值,数据类型支持[int8, int16, int32, int64, float16, float32]。
stddev (Tensor) - 标准差σ。大于0。数据类型支持[int8, int16, int32, int64, float16, float32]。
seed (int) - 随机种子。取值须为非负数。默认值:None,等同于0。
- 返回:
Tensor,shape应与输入 shape 与 mean 和 stddev 进行广播之后的shape相同。数据类型支持float32。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> 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)