I have an nx1 tensor and an nxm tensor. I want to gather values from the nx1 tensor using the nxm tensor.
For example
for input tensor([1, 2, 3, 4]) and
index tensor([[0, 3], [2, 1],[1, 3], [2,3]])
output should be
tensor([[1, 4], [3, 2], [2,4], [3,4])
How to use torch.gather for this purpose?
My following code gives error
t = torch.tensor([[1, 2, 3, 4]])
ind = torch.tensor([[0, 3], [2, 1],[1, 3], [2,3]])
torch.gather(t, 0, ind)

RuntimeError: index 2 is out of bounds for dimension 0 with size 1
Edit: You can do simple indexing to achieve this output.
t[ind]

Is this the best way to do this. I assume this involves broadcasting the input array.