repeat_interleave¶
- paddle. repeat_interleave ( x: Tensor, repeats: int | Tensor, axis: int | None = None, name: str | None = None ) Tensor [source]
-
Returns a new tensor which repeats the
x
tensor along dimensionaxis
using the entries inrepeats
which is a int or a Tensor.The image illustrates a typical case of the repeat_interleave operation. Given a tensor
[[1, 2, 3], [4, 5, 6]]
, with the repeat countsrepeats = [3, 2, 1]
and parameteraxis = 1
, it means that the elements in the 1st column are repeated 3 times, the 2nd column is repeated 2 times, and the 3rd column is repeated 1 time.The final output is a 2D tensor:
[[1, 1, 1, 2, 2, 3], [4, 4, 4, 5, 5, 6]]
.- Parameters
-
x (Tensor) – The input Tensor to be operated. The data of
x
can be one of float32, float64, int32, int64.repeats (Tensor|int) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
axis (int|None, optional) – The dimension in which we manipulate. Default: None, the output tensor is flatten.
name (str|None, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.
- Returns
-
Tensor, A Tensor with same data type as
x
.
Examples
>>> import paddle >>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]]) >>> repeats = paddle.to_tensor([3, 2, 1], dtype='int32') >>> out = paddle.repeat_interleave(x, repeats, 1) >>> print(out) Tensor(shape=[2, 6], dtype=int64, place=Place(cpu), stop_gradient=True, [[1, 1, 1, 2, 2, 3], [4, 4, 4, 5, 5, 6]]) >>> out = paddle.repeat_interleave(x, 2, 0) >>> print(out) Tensor(shape=[4, 3], dtype=int64, place=Place(cpu), stop_gradient=True, [[1, 2, 3], [1, 2, 3], [4, 5, 6], [4, 5, 6]]) >>> out = paddle.repeat_interleave(x, 2, None) >>> print(out) Tensor(shape=[12], dtype=int64, place=Place(cpu), stop_gradient=True, [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6])