On this page
torch.Tensor.unfold
Tensor.unfold(dimension, size, step) → Tensor-
Returns a view of the original tensor which contains all slices of size
sizefromselftensor in the dimensiondimension.Step between two slices is given by
step.If
sizedimis the size of dimensiondimensionforself, the size of dimensiondimensionin the returned tensor will be(sizedim - size) / step + 1.An additional dimension of size
sizeis appended in the returned tensor.- Parameters
Example:
>>> x = torch.arange(1., 8) >>> x tensor([ 1., 2., 3., 4., 5., 6., 7.]) >>> x.unfold(0, 2, 1) tensor([[ 1., 2.], [ 2., 3.], [ 3., 4.], [ 4., 5.], [ 5., 6.], [ 6., 7.]]) >>> x.unfold(0, 2, 2) tensor([[ 1., 2.], [ 3., 4.], [ 5., 6.]])
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.Tensor.unfold.html