I've got a 3D tensor x
(e.g 4x4x100). I want to obtain a subset of this by explicitly choosing elements across the last dimension. This would have been easy if I was choosing the same elements across last dimension (e.g. x[:,:,30:50]
but I want to target different elements across that dimension using the 2D tensor indices
which specifies the idx across third dimension. Is there an easy way to do this in numpy?
A simpler 2D example:
x = [[1,2,3,4,5,6],[10,20,30,40,50,60]]
indices = [1,3]
Let's say I want to grab two elements across third dimension of x
starting from points specified by indices
. So my desired output is:
[[2,3],[40,50]]
Update: I think I could use a combination of take()
and ravel_multi_index()
but some of the platforms that are inspired by numpy (like PyTorch) don't seem to have ravel_multi_index
so I'm looking for alternative solutions