Tensor indexing with another tensor - PyTorch Forums
https://discuss.pytorch.org/t/tensor-indexing-with-another-tensor/11448511.03.2021 · Hi, I usually index tensors with lists of indices, like x = torch.as_tensor([[1,2,3,4,5], [6,7,8,9,0]]) index = [[0, 1, 1], [1, 1, 2]] # tensor([2, 7, 8]) x[index] Now I need index to be a tensor object, but doing this, I get an error: x = torch.as_tensor([[1,2,3,4,5], [6,7,8,9,0]]) index = torch.as_tensor( [[0, 1, 1], [1, 1, 2]]) # IndexError: index 2 is out of bounds for dimension 0 with ...
PyTorch tensor advanced indexing - Stack Overflow
https://stackoverflow.com › pytorc...You can specify the corresponding row index as: import torch x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) y = torch.tensor([0, 2, ...