代码拉取完成,页面将自动刷新
torch.normal(mean, std, *, generator=None, out=None)
torch.normal(mean=0.0, std, *, out=None)
torch.normal(mean, std=1.0, *, out=None)
torch.normal(mean, std, size, *, out=None)
For more information, see torch.normal.
mindspore.ops.normal(shape, mean, stddev, seed=None)
For more information, see mindspore.ops.normal.
API function of MindSpore is consistent with that of PyTorch.
PyTorch: Four interface usages are supported.
mean
and std
are both Tensor, requiring the same number of members for mean
and std
. The shape of the return value matches the shape of mean
.mean
is the float type, std
is Tensor. The shape of the return value matches the shape of std
.std
is the float type, mean
is Tensor. The shape of the return value matches the shape of mean
.mean
and std
are both float types. The shape of the return value matches the shape of size
.MindSpore: The data types supported by mean
and std
are Tensor, and the shape of the return value is broadcast by shape
, mean
, and stddev
.
Categories | Subcategories | PyTorch | MindSpore | Differences |
---|---|---|---|---|
Parameters | Parameter 1 | - | shape | This value in MindSpore is used to broadcast the shape of the return value together with mean and stddev
|
Parameter 2 | mean | mean | The data type supported in MindSpore is Tensor. Tensor and float are supported in PyTorch, corresponding to different usages | |
Parameter 3 | std | stddev | The data type supported in MindSpore is Tensor. Tensor and float are supported in PyTorch, corresponding to different usages | |
Parameter 4 | generator | seed | For details, see General Difference Parameter Table | |
Parameter 5 | size | - | The shape of the return value in PyTorch, used under the specified interface usage | |
Parameter 6 | out | - | For details, see General Difference Parameter Table |
In PyTorch, 'mean' and 'std' are both Tensor.
# PyTorch
import torch
import numpy as np
mean = torch.tensor(np.array([[3, 4], [5, 6]]), dtype=torch.float32)
stddev = torch.tensor(np.array([[0.2, 0.3], [0.4, 0.5]]), dtype=torch.float32)
output = torch.normal(mean, stddev)
print(output.shape)
# torch.Size([2, 2])
# MindSpore
import mindspore as ms
import numpy as np
shape = (2, 2)
mean = ms.Tensor(np.array([[3, 4], [5, 6]]), ms.float32)
stddev = ms.Tensor(np.array([[0.2, 0.3], [0.4, 0.5]]), ms.float32)
output = ms.ops.normal(shape, mean, stddev)
print(output.shape)
# (2, 2)
In PyTorch, 'mean' is the float and 'std' is the Tensor.
# PyTorch
import torch
import numpy as np
mean = 3.0
stddev = torch.tensor(np.array([[0.2, 0.3], [0.4, 0.5]]), dtype=torch.float32)
output = torch.normal(mean, stddev)
print(output.shape)
# torch.Size([2, 2])
# MindSpore
import mindspore as ms
import numpy as np
shape = (2, 2)
mean = ms.Tensor(3.0, ms.float32)
stddev = ms.Tensor(np.array([[0.2, 0.3], [0.4, 0.5]]), ms.float32)
output = ms.ops.normal(shape, mean, stddev)
print(output.shape)
# (2, 2)
In PyTorch, 'mean' is Tensor, and 'std' is the float.
# PyTorch
import torch
import numpy as np
mean = torch.tensor(np.array([[3, 4], [5, 6]]), dtype=torch.float32)
stddev = 1.0
output = torch.normal(mean, stddev)
print(output.shape)
# torch.Size([2, 2])
# MindSpore
import mindspore as ms
import numpy as np
shape = (2, 2)
mean = ms.Tensor(np.array([[3, 4], [5, 6]]), ms.float32)
stddev = ms.Tensor(1.0, ms.float32)
output = ms.ops.normal(shape, mean, stddev)
print(output.shape)
# (2, 2)
In PyTorch, 'mean' and 'std' are both float.
# PyTorch
import torch
import numpy as np
mean = 3.0
stddev = 1.0
size = (2, 2)
output = torch.normal(mean, stddev, size)
print(output.shape)
# torch.Size([2, 2])
# MindSpore
import mindspore as ms
import numpy as np
shape = (2, 2)
mean = ms.Tensor(3.0, ms.float32)
stddev = ms.Tensor(1.0, ms.float32)
output = ms.ops.normal(shape, mean, stddev)
print(output.shape)
# (2, 2)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。