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

posted on 2020-11-27 19:48  cltt  阅读(1567)  评论(0编辑  收藏  举报

导航