How can I swap values in PyTorch Tensor?
I have the following tensor:
vector = torch.tensor([[1,5,3], [2,3,4]])

How can I swap values in the second axis?
e.g.
tensor([[1, 5, 3], [2, 3, 4]])
becomes:
tensor([[1, 3, 3], [2, 5, 4]])

You can use numpy's style of indexing :
&gt;&gt;&gt; vector = torch.tensor([[1,5,3], [2,3,4]])
tensor([[1, 3, 4],
        [2, 5, 3]])
&gt;&gt;&gt; vector[[0,1],1] = vector[[1,0],1]
&gt;&gt;&gt; vector 
tensor([[1, 3, 3],
        [2, 5, 4]])

In that case, we switch the value between the 0th and 1st index in the first dimension, only at the index 1 on the second dimension.
