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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With