int/list类型转tensor类型
python数据类型->Numpy数据类型->Pytorch的cup tensor->Pytorch的gpu tensor转载a为基本的int类型数据b=np.array(a), b为numpy数据类型c=torch.from_numpy(b),c为CPU的tensord=c.cuda(),d为GPU的tensor
·
python数据类型->Numpy数据类型->Pytorch的cpu tensor->Pytorch的gpu tensor
python数据类型->list类型->Pytorch的cpu tensor->Pytorch的gpu tensor
转载
a为基本的int类型数据
b=np.array(a)
, b为numpy数据类型
c=torch.from_numpy(b)
,c为CPU的tensor
d=c.cuda()
,d为GPU的tensor
a为基本的int类型数据
> `b=list(a)`, b为numpy数据类型
> `c=torch.tensor(b)`,c为CPU的tensor
> `d=c.cuda()`,d为GPU的tensor
补充:
data = torch.ones(2, 2)
print(data.dtype)
# torch.int64 #--这里就按照ones--对应int64类型
data = data.type(torch.float32) # 要接收类型已经改变的tensor数据,否则data本身是不会直接改变数据类型的
print(data.dtype)
torch.float32
list和tensor类型数据互转:
三种类型互转:https://blog.csdn.net/qq_41764621/article/details/126896448
更多推荐
活动日历
查看更多
直播时间 2025-02-26 16:00:00


直播时间 2025-01-08 16:30:00


直播时间 2024-12-11 16:30:00


直播时间 2024-11-27 16:30:00


直播时间 2024-11-21 16:30:00


所有评论(0)