int -> float¶
torch.tensor(x, dtype=数据格式)
import torch
a = [1, 2, 3, 4]
a1 = torch.tensor(a)
a_float = torch.tensor(a1, dtype=torch.float32)
a_int64 = torch.tensor(a1, dtype=torch.int64)
print(a1.dtype)
print(a_float.dtype)
print(a_int64.dtype)
torch.int64
torch.float32
torch.int64
References¶
-PyTorch 学习笔记——Tensor 张量的数据类型的转化、Tensor 常见的数据类型、快速创建 Tensor
评论