快速鍵

torch.Tensor.unfold

Tensor.unfold(dimension, size, step) Tensor

返回原始張量的視圖,該視圖包含來自 self 張量在維度 dimension 中大小為 size 的所有切片。

兩個切片之間的步長由 step 給出。

如果 sizedimself 的維度 dimension 的大小,則返回的張量中維度 dimension 的大小將為 (sizedim - size) / step + 1

大小為 size 的額外維度附加在返回的張量中。

參數
  • dimension (int) – 展開發生的維度

  • size (int) – 每個展開切片的大小

  • step (int) – 每個切片之間的步長

範例

>>> 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.]])

文件

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources