We can index a Tensor with another Tensor and sometimes we can successfully index a Tensor with a NumPy array. The following code works for some dims:
(2, 3)(2, 3, 2)(2, 3, 2, 2)(2, 100, 2, 2)(32, 100, 2, 2)
but not for others:
(3, 3)(4, 3, 2)(5, 100, 2, 2)
import torch
def foo(dims):
a = torch.zeros(dims)
b = a.long()
a[b] # always works
a[b.numpy()] # sometimes works
If you try any of the examples from the second list you will get:
IndexError: too many indices for tensor of dimension (whatever dim is)
Is this a bug or should we rather say that NumPy was never meant to be an indexing object for Tensors and hence we should consider it unexpected behaviour?
PyTorch versions 1.9.0 and 1.9.1.