Hi there,
I’m trying something along those lines:
I have indices to a 3D volume (b
), and b.nonzero()
gives me (N, 3) indices to index with.
Now I have another 3D volume with some more dimensions (a
) and I would like to get something of the shape (BS, F, N) with N being the number of nonzero samples in b
.
a = torch.randn(1,2, 10,10,10)
b = torch.randn( 10,10,10)
a[:, :, (b > 0).nonzero(as_tuple=True)]
Leading to
TypeError: only integer tensors of a single element can be converted to an index
Obviously b[(b > 0).nonzero(as_tuple=True)]
works, but I can’t seem to index the first two dimensions differently (i.e. with something else but a LongTensor).
The only way I have in mind to do this would be a torch.nn.functional.grid_sample()
with nearest mode after dividing the indices by the respective dimension lengths, but that seems unnecessary and slow.
Any suggestions on how I can achieve the above behavior?