其他分享
首页 > 其他分享> > tensor 类型转换

tensor 类型转换

作者:互联网

在Tensor后加 .long(), .int(), .float(), .double()等即可,也可以用.to()函数进行转换,所有的Tensor类型可参考https://pytorch.org/docs/stable/tensors.html

import torch
a = torch.DoubleTensor((3, 2))

print(a.dtype)
a = a.float()

print(a.dtype)

torch.float64
torch.float32

标签:类型转换,torch,tensor,后加,dtype,float,print,Tensor
来源: https://www.cnblogs.com/tingtin/p/14049975.html