torch.is_floating_point(input)

torch.is_floating_point(input)

  • input: 输入张量

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

  • 浮点数据类型:torch.float64、torch.float32、torch.float16 、 torch.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
相关推荐
李帅朋16 分钟前
INP-Former阅读笔记
笔记·深度学习·计算机视觉
AI源码1 小时前
基于深度学习的日常服饰分类与推荐系统设计
人工智能·深度学习·分类
2401_868534781 小时前
【网络安全
网络·python
一条大祥脚11 小时前
TVM 的前世今生:从深度学习编译器到 AI 基础设施
人工智能·深度学习·tvm
❁满城风絮*12 小时前
Claude Code 学习总结
python·agent·claude
维克兜率天14 小时前
【维克】复合型CTA:趋势+套利的双轮驱动
python·学习方法
伞伞悦读14 小时前
【第76期】两张3行表左连接变5行:主键、validate与未匹配排查完整教程
人工智能·python
用户83562907805115 小时前
使用 Python 在 Excel 中添加和自定义迷你图
后端·python
用户83562907805115 小时前
使用 Python 在 Excel 图表中添加趋势线与回归方程
后端·python
AI源码15 小时前
基于深度学习的音乐风格分类系统
人工智能·深度学习