TUTORIALAI & dataFETCHED

PyTorch torch.fmin 函数

PyTorch torch.fmin 函数 Pytorch torch 参考手册 torch.fmin 是 PyTorch 中用于逐元素取最小值的函数(忽略NaN)。当输入中包含NaN时,torch.minimum会返回NaN,而torch.fmin会忽略NaN并返回非NaN值。 函数定义 torch.fmin(input, other) 使用示例 实例 [mycode4 type='python'..

Updated 7/16/2026

Tutorial detail pages default to noindex.

PyTorch torch.fmin 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.fmin 是 PyTorch 中用于逐元素取最小值的函数(忽略NaN)。当输入中包含NaN时,torch.minimum会返回NaN,而torch.fmin会忽略NaN并返回非NaN值。

函数定义

torch.fmin(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.fmin(x, y)
print(result)

输出结果为:

tensor([1., 5., 2.])

Pytorch torch 参考手册 Pytorch torch 参考手册