torch.tensor(data, dtype=None, device=None, requires_grad=False)
>>> a=torch.tensor([1,2])
>>> a.type()
'torch.LongTensor'
>>> a=torch.tensor([1.,2.])
>>> a.type()
'torch.FloatTensor'
>>> a=np.zeros(2,dtype=np.float64)
>>> a=torch.tensor(a)
>>> a.type()
'torch.DoubleTensor'
a = torch.Tensor(2,3)
print(a, a.type())
# tensor([[1.3563e-19, 1.7753e+28, 1.3458e-14],
# [2.3335e-09, 2.3301e-09, 2.3301e-09]]) torch.FloatTensor
b = torch.FloatTensor(2,3)
print(b, b.type())
# tensor([[-4.0056e+18, 4.5737e-41, -4.0056e+18],
# [ 4.5737e-41, 0.0000e+00, 0.0000e+00]]) torch.FloatTensor
a = torch.tensor([2,3])
print(a, a.type())
# tensor([2, 3]) torch.LongTensor
b = torch.Tensor([2,3])
print(b, b.type())
# tensor([2., 3.]) torch.FloatTensor
c = torch.FloatTensor([2,3])
print(c, c.type())
# tensor([2., 3.]) torch.FloatTensor
部分参考:https://www.jianshu.com/p/d83149dcdd79