Pytorch Type change is not work

Why Pytorch Type change is not work?

Pytorch is 0.4.0

input:
a = torch.FloatTensor(3, 5)
a.type(torch.IntTensor)
print(a.type())

output:
torch.FloatTensor


the right code is:
a = a.type(torch.IntTensor)
:joy:

the right code is:
a = torch.IntTensor(3, 5)
a = a.type(torch.float)
a.type()

:grinning:

Yes, the tensor.type(...) (and tensor.to(...), as well as most other tensor functions) will return a new tensor instead of modifying a tensor in-place.

1 Like