PyTorch torch.isposinf 函数

约 333 字 更新于 2026-11-18 5iyo.com

PyTorch torch.isposinf 函数


torch.isposinf 是 PyTorch 中用于检查是否是正无穷的函数。返回一个布尔张量,对于每个元素,如果是正无穷大则为True。

函数定义

torch.isposinf(input)

使用示例

实例

import torch

# 创建包含不同数值的张量
x = torch.tensor([1.0, float('inf'), float('-inf'), 2.0])

# 检查是否是正无穷
result = torch.isposinf(x)
print(result)

输出结果为:

tensor([False, True, False, False])