mars.tensor.repeat#

mars.tensor.repeat(a, repeats, axis=None)[来源]#

重复张量的元素。

Parameters
  • a (array_like) – 输入张量。

  • 重复次数 (整数张量 包含 整数) – 每个元素的重复次数。 repeats 被广播以适应给定轴的形状。

  • axis (int, 可选) – 沿着重复值的轴。默认情况下,使用扁平化的输入张量,并返回一个扁平化的输出张量。

Returns

repeated_tensor – 输出数组,其形状与 a 相同,除了在给定轴上。

Return type

张量

另请参阅

tile

对张量进行切片。

示例

>>> import mars.tensor as mt
>>> mt.repeat(3, 4).execute()
array([3, 3, 3, 3])
>>> x = mt.array([[1,2],[3,4]])
>>> mt.repeat(x, 2).execute()
array([1, 1, 2, 2, 3, 3, 4, 4])
>>> mt.repeat(x, 3, axis=1).execute()
array([[1, 1, 1, 2, 2, 2],
       [3, 3, 3, 4, 4, 4]])
>>> mt.repeat(x, [1, 2], axis=0).execute()
array([[1, 2],
       [3, 4],
       [3, 4]])