tile

paddle. tile ( x, repeat_times, name=None ) [源代码]

根据参数 repeat_times 对输入 x 的各维度进行复制。平铺后,输出的第 i 个维度的值等于 x.shape[i]*repeat_times[i]

x 的维数和 repeat_times 中的元素数量应小于等于 6。

参数

  • x (Tensor) - 输入的 Tensor,数据类型为:bool、float16、float32、float64、int32 或 int64。

  • repeat_times (list|tuple|Tensor) - 指定输入 x 每个维度的复制次数。如果 repeat_times 的类型是 list 或 tuple,它的元素可以是整数或者数据类型为 int32 的 1-D Tensor。如果 repeat_times 的类型是 Tensor,则是数据类型为 int32 的 1-D Tensor。

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

返回

Tensor,数据类型与 x 相同。返回值的第 i 维的大小等于 x[i] * repeat_times[i]

代码示例

>>> import paddle

>>> data = paddle.to_tensor([1, 2, 3], dtype='int32')
>>> out = paddle.tile(data, repeat_times=[2, 1])
>>> print(out)
Tensor(shape=[2, 3], dtype=int32, place=Place(cpu), stop_gradient=True,
[[1, 2, 3],
 [1, 2, 3]])

>>> out = paddle.tile(data, repeat_times=(2, 2))
>>> print(out)
Tensor(shape=[2, 6], dtype=int32, place=Place(cpu), stop_gradient=True,
[[1, 2, 3, 1, 2, 3],
 [1, 2, 3, 1, 2, 3]])

>>> repeat_times = paddle.to_tensor([1, 2], dtype='int32')
>>> out = paddle.tile(data, repeat_times=repeat_times)
>>> print(out)
Tensor(shape=[1, 6], dtype=int32, place=Place(cpu), stop_gradient=True,
[[1, 2, 3, 1, 2, 3]])

使用本API的教程文档