九点韶留学

关注

pytorch如何转换tensor的类型dtype

九点韶留学

关注

阅读 68

2023-02-23


比如现在要将 float 类型的 tensor 转换为 long 类型:

# 两种方法都可以
a = a.long()
a = torch.tensor(a, dtype=torch.long)

同理,如果是改为其他类型,则把 long 替换为对应的类型就行

相关推荐

b91bff6ffdb5

ValueError: Tensor conversion requested dtype string for Tensor with dtype float32

b91bff6ffdb5 73 0 0

妖妖妈

报错 Tensor conversion requested dtype string for Tensor with dtype float32

妖妖妈 66 0 0

程序小小黑

(已解决)报错 ValueError: Tensor conversion requested dtype float32 for Tensor with dtype resource

程序小小黑 193 0 0

紫荆峰

Pytorch基础(二)- Tensor数据类型

紫荆峰 89 0 0

云卷云舒xj

【pytorch】带batch的tensor类型图像显示

云卷云舒xj 74 0 0

yongxinz

Pytorch中torch.Tensor和torch.tensor()以及其他Tensor类型的区别

yongxinz 53 0 0

Aliven888

译(五十)-Pytorch转换Tensor至numpy数组

Aliven888 84 0 0

承蒙不弃

PyTorch~Tensor

承蒙不弃 37 0 0

gy2006_sw

深度学习03:PyTorch的数据类型Tensor

gy2006_sw 99 0 0

程序员知识圈

pytorch中将tensor转换为numpy时报错

程序员知识圈 197 0 0

精彩评论(0)

0 0 举报