PyTorch torch.max 関数
torch.maxは PyTorch でテンソルの最大値を計算するための関数です。
関数定義
torch.max(input, dim, keepdim, out)
使用例
実例
import torch
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
# 全体の最大値
print("全体の最大値:", torch.max(x))
# 次元に沿った最大値
print("dim=0 の最大値:", torch.max(x, dim=0))
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
# 全体の最大値
print("全体の最大値:", torch.max(x))
# 次元に沿った最大値
print("dim=0 の最大値:", torch.max(x, dim=0))
出力結果は次のとおりです:
全局最大: tensor(6) dim=0 最大: torch.return_types.max(values=tensor([4, 5, 6]), indices=tensor([1, 1, 1]))
その他の拡張
Pytorch torch リファレンスマニュアル