In pytorch I have a multi-dimensional tensor, call it X
X = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], ...]
Now I would like to select a different column index for each row like so
indices = [[0], [1], [0], [2], ...]
# now I expect following values to be returned:
[[1], [5], [7], [12], ...]
also I would like to achieve the opposite so that for the given indices I get
[[2, 3], [4, 6], [8, 9], [10, 11]]
Is there a "simple" way to achieve this without a for loop? I would be grateful for any ideas.