PyTorch torch.is_floating_point 函数

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

PyTorch torch.is_floating_point 函数


torch.is_floating_point 是 PyTorch 中用于检查张量数据类型是否为浮点类型的函数。

函数定义

torch.is_floating_point(input)

使用示例

实例

import torch

# 浮点数张量
x = torch.tensor([1.0, 2.0, 3.0])
print("浮点数:", torch.is_floating_point(x))

# 整数张量
y = torch.tensor([1, 2, 3])
print("整数:", torch.is_floating_point(y))

输出结果为:

浮点数: True
整数: False