import torch
input=torch.Tensor([[1,-1],
[-1,3]])
print(input.type())
代码运行得到的结果:
torch.FloatTensor
如果将Tensor更改成tensor,则代码运行的结果:
torch.LongTensor
根据查阅的资料,以及自己实践运行的结果,可知:Tensor得到的张量的数据类型默认是FloatTensor;而tensor得到的张量的数据类型默认是LongTensor。
如果在代码中,分别指定数据类型会有怎样的结果呢?
import torch
input=torch.tensor([[1,-1],
[-1,3]],dtype=torch.float64)
print(input.type())
运行结果:
torch.DoubleTensor
但是对于Tensor函数,则出现报错:
new() received an invalid combination of arguments - got (list, dtype=torch.dtype), but expected one of:
* (*, torch.device device)
didn't match because some of the keywords were incorrect: dtype
* (torch.Storage storage)
* (Tensor other)
* (tuple of ints size, *, torch.device device)
* (object data, *, torch.device device)
Tensor输出的数据类型不能被改变,tensor的数据类型可以根据需要变化。