torch.fmax#
- torch.fmax(input, other, *, out=None) Tensor #
计算
input
和other
的逐元素最大值。This is like
torch.maximum()
except it handles NaNs differently: if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the maximum. Only if both elements are NaN is NaN propagated.This function is a wrapper around C++’s
std::fmax
and is similar to NumPy’sfmax
function.Supports broadcasting to a common shape, type promotion, and integer and floating-point inputs.
示例
>>> a = torch.tensor([9.7, float('nan'), 3.1, float('nan')]) >>> b = torch.tensor([-2.2, 0.5, float('nan'), float('nan')]) >>> torch.fmax(a, b) tensor([9.7000, 0.5000, 3.1000, nan])