a = [4,5,6,3,5]
b = torch.tensor([2])
print(a[:b])
>>>[4,5]
b
is torch.tensor
, I wonder why it can be used as an index value for slicing, performing like an int
type?
a = [4,5,6,3,5]
b = torch.tensor([2])
print(a[:b])
>>>[4,5]
b
is torch.tensor
, I wonder why it can be used as an index value for slicing, performing like an int
type?
Hi,
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.