repeat_interleave

paddle. repeat_interleave ( x, repeats, axis=None, name=None ) [source]

Returns a new tensor which repeats the x tensor along dimension axis using the entries in repeats which is a int or a Tensor.

Parameters
  • x (Tensor) – The input Tensor to be operated. The data of x can be one of float32, float64, int32, int64.

  • repeats (Tensor or int) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.

  • axis (int, optional) – The dimension in which we manipulate. Default: None, the output tensor is flatten.

  • name (str, 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])