mindspore.ops.Tile

查看源文件
class mindspore.ops.Tile[源代码]

按照给定的次数复制输入Tensor。

更多参考详见 mindspore.ops.tile()

输入:
  • input (Tensor) - 需要被复制的Tensor,设其shape为 (x1,x2,...,xS)

  • dims (tuple[int]) - 指定复制次数的参数,参数类型为tuple,数据类型为整数,如 (y1,y2,...,yS) ,只支持常量值。

说明

在Ascend平台上, dims 参数的个数不大于8,当前不支持超过4个维度同时做repeat的场景。

输出:

Tensor,具有与 input 相同的数据类型。假设 dims 的长度为 dinput 的维度为 input.diminput 的shape为 (x1,x2,...,xS)

  • 如果 input.dim = d ,将其相应位置的shape相乘,输出的shape为 (x1y1,x2y2,...,xSyS)

  • 如果 input.dim < d ,在 input 的shape的前面填充1,直到它们的长度一致。例如将 input 的shape设置为 (1,...,x1,x2,...,xS) ,然后可以将其相应位置的shape相乘,输出的shape为 (1y1,...,xRyR,xSyS)

  • 如果 input.dim > d ,在 dims 的前面填充1,直到它们的长度一致。例如将 dims 设置为 (1,...,y1,y2,...,yS) ,然后可以将其相应位置的shape相乘,输出的shape为 (x11,...,xRyR,xSyS)

异常:
  • TypeError - dims 不是tuple或者其元素并非全部是int。

  • ValueError - dims 的元素并非全部大于或等于0。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> tile = ops.Tile()
>>> input = Tensor(np.array([[1, 2], [3, 4]]), mindspore.float32)
>>> dims = (2, 3)
>>> output = tile(input, dims)
>>> print(output)
[[1.  2.  1.  2.  1.  2.]
 [3.  4.  3.  4.  3.  4.]
 [1.  2.  1.  2.  1.  2.]
 [3.  4.  3.  4.  3.  4.]]
>>> dims = (2, 3, 2)
>>> output = tile(input, dims)
>>> print(output)
[[[1. 2. 1. 2.]
  [3. 4. 3. 4.]
  [1. 2. 1. 2.]
  [3. 4. 3. 4.]
  [1. 2. 1. 2.]
  [3. 4. 3. 4.]]
 [[1. 2. 1. 2.]
  [3. 4. 3. 4.]
  [1. 2. 1. 2.]
  [3. 4. 3. 4.]
  [1. 2. 1. 2.]
  [3. 4. 3. 4.]]]