PyTorch torch.max 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

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))

出力結果は次のとおりです:

全局最大: tensor(6)
dim=0 最大: torch.return_types.max(values=tensor([4, 5, 6]), indices=tensor([1, 1, 1]))

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張