Search code examples
luatorch

Torch - How to change tensor type?


I created a permutation of the numbers from 1 to 3.

th> y = torch.randperm(3 );
th> y
 3
 2
 1
[torch.DoubleTensor of size 3]

Now, I want to convert y to a Torch.LongTensor. How can I do that?


Solution

  • 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.