How to index tensor with high dimensional tensor
I have two tensors x for values and y for indexing. x.shape and y.shape are the same except the last dimension.
For example:
x=torch.tensor([[1, 6, 7, 5, 6],
        [8, 6, 7, 8, 4],
        [2, 8, 3, 5, 6]])
# x.shape:(3,5)
y=torch.tensor([[1, 2],
        [2, 3],
        [2, 2]])
# y.shape:(3,2)

Is there a simple way to slice it x[y]so that the result is:
torch.tensor([6,7],[7,8],[3,3])

What if x and y are higher dimensional tensors:
x.shape=(a,b,c,d)
y.shape=(a,b,c,e)
# a, b, c, d, e are positive integer


That's exactly what torch.gather does.
&gt;&gt; torch.gather(x, -1, y) # index along the last dimension
tensor([[6, 7],
        [7, 8],
        [3, 3]])

The exact same command works with your high-dimensional case as well.
