PyTorch torch.std 関数
torch.stdは、PyTorch においてテンソルの標準偏差を返すために使用される関数です。標準偏差は分散の平方根であり、データのばらつきの度合いを表します。
関数定義
torch.std(input, dim, unbiased, keepdim=False)
使用例
実例
import torch
x = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0])
# すべての要素の標準偏差を返す
print("標準偏差:", torch.std(x))
# dim=0 に沿った標準偏差
y = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
print("dim=0 標準偏差:", torch.std(y, dim=0))
print("dim=1 標準偏差:", torch.std(y, dim=1))
x = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0])
# すべての要素の標準偏差を返す
print("標準偏差:", torch.std(x))
# dim=0 に沿った標準偏差
y = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
print("dim=0 標準偏差:", torch.std(y, dim=0))
print("dim=1 標準偏差:", torch.std(y, dim=1))
出力結果は次のとおりです:
标准差: tensor(1.5811) dim=0 标准差: tensor([1.5000, 1.5000, 1.5000]) dim=1 标准差: tensor([1.0000, 1.0000])
その他の拡張
Pytorch torch リファレンスマニュアル