PyTorch torch.isneginf 函数
torch.isneginf 是 PyTorch 中用于检查是否是负无穷的函数。返回一个布尔张量,对于每个元素,如果是负无穷大则为True。
函数定义
torch.isneginf(input)
使用示例
实例
import torch
# 创建包含不同数值的张量
x = torch.tensor([1.0, float('inf'), float('-inf'), 2.0])
# 检查是否是负无穷
result = torch.isneginf(x)
print(result)
# 创建包含不同数值的张量
x = torch.tensor([1.0, float('inf'), float('-inf'), 2.0])
# 检查是否是负无穷
result = torch.isneginf(x)
print(result)
输出结果为:
tensor([False, False, True, False])

Pytorch torch 参考手册