How to select from a 3D tensor using mask of 1D

This is similar to Indexing Multi-dimensional Tensors based on 1D tensor of indices

I guess what you need is :

A.gather(1, L.view(-1, 1, 1).expand(A.size(0), 1, A.size(2)))

I haven’t found anything better for now…

5 Likes