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