比较与torch.std_mean的功能差异
torch.std_mean
torch.std_mean(
input,
dim,
unbiased=True,
keepdim=False
)
更多内容详见torch.std_mean。
mindspore.ops.ReduceMean
class mindspore.ops.ReduceMean(keep_dims=False)(
input_x,
axis=()
)
更多内容详见mindspore.ops.ReduceMean。
使用方式
PyTorch:计算指定维度数据的标准差和平均值。
MindSpore:计算指定维度数据的平均值。
代码示例
from mindspore import Tensor
import mindspore.ops as ops
import torch
import numpy as np
# In MindSpore, only the mean of given dimension will be returned.
input_x = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32))
op = ops.ReduceMean(keep_dims=True)
output = op(x=input_x, axis=1)
print(output)
# Out:
# [[1.5]
# [3.5]]
# In torch, both std and mean of given dimensions will be returned.
input_x = torch.tensor(np.array([[1, 2], [3, 4]]).astype(np.float32))
output = torch.std_mean(input=input_x, dim=1)
std, mean = output
print('std: {}'.format(std))
print('mean: {}'.format(mean))
# Out:
# torch.tensor([0.7071, 0.7071])
# torch.tensor([1.5000, 3.5000])