Combine index and value of tenor to from a new tensor
I have a  tensor like a = torch.tensor([1,2,0,1,2]). I want to calculate a tensor b which has indices and values of tensor a such that:

b = tensor([ [0,1], [1,2], [2,0], [3,1], [4,2] ]).

Edit: a[i] is &gt;=  0.

One way of doing this is:

b = torch.IntTensor(list(zip(range(0, list(a.size())[0], 1), a.numpy())))


Output:

tensor([[0, 1],
        [1, 2],
        [2, 0],
        [3, 1],
        [4, 2]], dtype=torch.int32)


Alternatively, you can also use torch.cat() as below:

a = torch.tensor([1,2,0,1,2])
indices = torch.arange(0, list(a.size())[0])
res = torch.cat([indices.view(-1, 1), a.view(-1, 1)], 1) 


Output:

tensor([[0, 1],
        [1, 2],
        [2, 0],
        [3, 1],
        [4, 2]])

