repeat_interleave

paddle. repeat_interleave ( x, repeats, axis=None, name=None ) [源代码]

沿着指定轴 axis 对输入 x 进行复制,创建并返回到一个新的Tensor。当 repeats1-D Tensor 时, repeats 长度必须和指定轴 axis 维度一致, repeats 对应位置的值表示 x 对应位置元素需要复制的次数。 当 repeats 为 int 时, x 沿指定轴 axis 上所有元素复制 repeats 次。

参数

  • x (Tensor)– 输入Tensor。 x 的数据类型可以是float32,float64,int32,int64。

  • repeats (Tensor, int)– 包含复制次数的 1-D Tensor 或指定的复制次数。

  • axis (int, 可选) – 指定对输入 x 进行运算的轴,若未指定,默认值为 None,使用输入 Tensor 的 flatten 形式。

  • name (str,可选)- 具体用法请参见 Name ,一般无需设置,默认值为None。

返回

  • Tensor: 返回一个数据类型同输入的Tensor。

代码示例

import paddle

x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]])
repeats  = paddle.to_tensor([3, 2, 1], dtype='int32')

paddle.repeat_interleave(x, repeats, 1)
# [[1, 1, 1, 2, 2, 3],
#  [4, 4, 4, 5, 5, 6]]

paddle.repeat_interleave(x, 2, 0)
# [[1, 2, 3], [1, 2, 3], [4, 5, 6], [4, 5, 6]]

paddle.repeat_interleave(x, 2, None)
# [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]