PyTorch torch.maximum 関数


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

torch.maximumは PyTorch で要素ごとに最大値を取るために使用される関数です。2つのテンソルの対応する要素の最大値から構成される新しいテンソルを返します。

関数定義

torch.maximum(input, other)

使用例

実例

import torch

# 2つのテンソルを作成する
x = torch.tensor([3, 1, 4])
y = torch.tensor([1, 5, 2])

# 要素ごとに最大値を取る
result = torch.maximum(x, y)
print(result)

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

tensor([3, 5, 4])

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

その他の拡張