Indexing Multi-dimensional Tensors based on 1D tensor of indices
Hi, I have currently tried the following methods: Using gather:
seq_len = seq_len.view(-1, 1, 1).expand(output.size(0), 1, output.size(2))
output_extracted = torch.gather(output, 1, seq_len)
 Using index_select:
output_extracted = torch.cat([torch.index_select(output[i], 0, seq_len[i]) for i in xrange(output.size(0)])

dasguptar
chenyangh
dasguptar