paddle. unfold ( x, axis, size, step, name=None ) [source]

View x with specified shape, stride and offset, which contains all slices of size from x in the dimension axis.

Note that the output Tensor will share data with origin Tensor and doesn’t have a Tensor copy in dygraph mode.

  • x (Tensor) – An N-D Tensor. The data type is float32, float64, int32, int64 or bool

  • axis (int) – The axis along which the input is unfolded.

  • size (int) – The size of each slice that is unfolded.

  • step (int) – The step between each slice.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.


Tensor, A unfold Tensor with the same data type as x.


>>> import paddle
>>> paddle.base.set_flags({"FLAGS_use_stride_kernel": True})

>>> x = paddle.arange(9, dtype="float64")

>>> out = paddle.unfold(x, 0, 2, 4)
>>> print(out)
Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
[[0., 1.],
 [4., 5.]])