PyTorch torch.mean 関数
torch.meanPyTorch でテンソルの平均を計算するための関数です。
関数定義
torch.mean(input, dim, keepdim, dtype, out)
使用例
例
import torch
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
# 全要素の平均を計算
print("全体の平均:", torch.mean(x))
# dim=0 に沿って平均を計算
print("dim=0 の平均:", torch.mean(x, dim=0))
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
# 全要素の平均を計算
print("全体の平均:", torch.mean(x))
# dim=0 に沿って平均を計算
print("dim=0 の平均:", torch.mean(x, dim=0))
出力結果は次のとおりです:
全局均值: tensor(3.5000) dim=0 均值: tensor([2.5000, 3.5000, 4.5000])
その他の拡張
Pytorch torch リファレンスマニュアル