PyTorch torch.fmax function
PyTorch torch reference manual
torch.fmax 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 a non-NaN value.
Function definition
torch.fmax(input, other)
Usage examples
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
)
(
result
)
The output is:
tensor([3., 5., 4.])