PyTorch torch.fmax 関数


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

torch.fmaxPyTorch で要素ごとに最大値を取るための関数です(NaNを無視します)。入力にNaNが含まれる場合、torch.maximumはNaNを返しますが、torch.fmaxはNaNを無視して非NaN値を返します。

関数定義

torch.fmax(input, other)

使用例

実例

import torch

# NaNを含むテンソルを作成
x = torch.tensor([3.0, float('nan'), 4.0])
y = torch.tensor([1.0, 5.0, 2.0])

# 要素ごとに最大値を取得(NaNを無視)
result = torch.fmax(x, y)
print(result)

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

tensor([3., 5., 4.])

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

その他の拡張