Torch - How to change tensor type?
use .to
method of torch as follows:
y = y.to(torch.long)
More details about torch tensor type/ops can be found here
https://pytorch.org/docs/stable/tensors.html
For pytorch users, because searching for change tensor type in pytorch in google brings to this page, you can do:
y = y.type(torch.LongTensor)
y = y.long()
does the job. There are similar methods for other data types, such as int
, char
, float
and byte
.
You can check different dtypes here.