pytorch-tensor创建,类型转换

1.查看数据类型
常用类型有 : torch.IntTensor、 torch.FloatTensor
torch.Tensor是默认的tensor类型(torch.FloatTensor)的简称
tensor.dtype
2.类型转换

方法一:简单后缀转换

tensor.int()
tensor.float()
tensor.double()

方法二:使用torch.type()函数

tensor.type(torch.FloatTensor)

方法三:使用type_as(tensor)将tensor转换为指定tensor的类型

3.tensor创建--指定维度和数据类型
torch.IntTensor(3,4).zero_()
torch.Tensor(3,4).zero_()

猜你喜欢

转载自www.cnblogs.com/yeran/p/11145805.html