How to index a tensor with a tensor?

Is there any method that can easily used to index a one dimensional tensor with a tensor.
For example:

y = torch.Tensor([[1,2],[3,4])

I want to get something like x[y] = [[1,2],[3,4]]

But pytorch tensor do not accept different index matrix shape.

1 Like

I think I’ve found the solution. Pytorch support gather operation, great work!:blush:

We’ll have to add support for this kind of indexing too. For now you have to use gather.