PyTorch torch.fmax Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.fmaxIt is a function in PyTorch for element-wise maximum (ignoring NaN). When the input contains NaN, torch.maximum returns NaN, while torch.fmax ignores NaN and returns non-NaN values.

Function Definition

torch.fmax(input, other)

Usage Example

Example

import torch

# Create a tensor containing NaN
x = torch.tensor([3.0, float('nan'), 4.0])
y = torch.tensor([1.0, 5.0, 2.0])

# Element-wise maximum (ignoring NaN)
result = torch.fmax(x, y)
print(result)

The output result is:

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

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions