How can I select single indices over a dimension in pytorch?
Assume I have a tensor sequences of shape [8, 12, 2]. Now I would like to make a selection of that tensor for each first dimension which results in a tensor of shape [8, 2]. The selection over dimension 1 is specified by indices stored in a long tensor indices of shape [8].

I tried this, however it selects each index in indices for each first dimension in sequences instead of only one.

sequences[:, indices]


How can I make this query without a slow and ugly for loop?

sequences[torch.arange(sequences.size(0)), indices]

