现在位置: 首页 > PyTorch 教程 > 正文

PyTorch torch.is_floating_point 函数


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

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

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