Returns a new Tensor
which is a narrowed version of the current one: the dimension dim
is narrowed
from index
to index+size-1
.
> x = torch.Tensor(5, 6):zero() > print(x) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [torch.Tensor of dimension 5x6] > y = x:narrow(1, 2, 3) -- narrow dimension 1 from index 2 to index 2+3-1 > y:fill(1) -- fill with 1 > print(y) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [torch.Tensor of dimension 3x6] > print(x) -- memory in x has been modified! 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 [torch.Tensor of dimension 5x6]