Why can `torch.tensor` be an index value for slicing?

a = [4,5,6,3,5]
b = torch.tensor([2])

b is torch.tensor, I wonder why it can be used as an index value for slicing, performing like an int type?


Yes integer type Tensors can be used this way.

I see that you added the autograd label. It is not a problem for autograd because integer type Tensor can never require gradients.