Combining basic and advanced indexing in PyTorch

Is it possible to combine basic and advanced indexing in PyTorch? I have a 3x128x128x128 array which basically stores a 3D vector at each voxel in a 128x128x128 array of voxels. I want to get the vectors stored at a selected few of those voxels.
I use the following code to get those vectors:

offset_vectors = my_array[:,voxel_indices]

Here, “voxel_indices” is a tuple of 3 tensors representing the indices of the voxels of interest along the three dimensions (The tuple of tensors is in the same format as returned by PyTorch’s nonzero method call with as_tuple=True).

But, the above call gives me the following error message:
ValueError: only one element tensors can be converted to Python scalars

Am I doing something wrong or Pytorch doesn’t allow combining basic and advanced indexing as done above? Numpy does allow such combination (


Do the index tensors in voxel_indices have the same shape or would you need to broadcast?
In the former case, you should be able to index the original tensor via:

x[:, idx[0], idx[1], idx[2]]