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

原文地址:https://www.cnblogs.com/tingtin/p/14049975.html