torch.is_floating_point(input)

torch.is_floating_point(input)

  • input: 输入张量

如果输入的数据类型是 浮点数据类型 ,则返回 True。否则返回False。

  • 浮点数据类型:torch.float64torch.float32torch.float16torch.bfloat16
python 复制代码
import torch

# 创建一个浮点数张量
float_tensor = torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32)

# 检查张量是否为浮点类型
is_float = torch.is_floating_point(float_tensor)

print(is_float)  # 输出: True

# 创建一个整数张量
int_tensor = torch.tensor([1, 2, 3], dtype=torch.int32)

# 检查张量是否为浮点类型
is_float = torch.is_floating_point(int_tensor)

print(is_float)  # 输出: False

# 创建一个复数张量
complex_tensor = torch.tensor([1 + 2j, 3 - 4j, 5 + 6j], dtype=torch.complex64)

# 检查张量是否为浮点类型
is_float = torch.is_floating_point(complex_tensor)

print(is_float)  # 输出: False
相关推荐
databook9 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室10 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三11 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271115 小时前
Python之语言特点
python
刘立军15 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机18 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机20 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i21 小时前
django中的FBV 和 CBV
python·django
c8i21 小时前
python中的闭包和装饰器
python
惯导马工21 小时前
【论文导读】ORB-SLAM3:An Accurate Open-Source Library for Visual, Visual-Inertial and
深度学习·算法