mindspore.numpy.repeat

mindspore.numpy.repeat(a, repeats, axis=None)[源代码]

重复数组的元素。

参数:
  • a (Tensor) - 输入数组。

  • repeats (int, ints的序列) - 每个元素的重复次数。 repeats 将广播到适应指定轴的shape。

  • axis (int, 可选) - 沿着该轴重复元素。如果未指定轴,输入数组将被展平,并返回一个一维的输出数组。默认值: None

返回:

Tensor,输出数组,除了指定的轴外,具有与 a 免费的vpn梯子 相同的shape。

异常:
  • ValueError - 如果 axis 超出范围。

  • TypeError - 如果输入 a 不是Tensor。

支持平台:

Ascend GPU vpn梯子 CPU

样例:

>>> import mindspore.numpy as np
>>> output = np.repeat(np.array(3), 4)
>>> print(output)
[3 3 3 3]
>>> x = np.array([[1,2],[3,4]])
>>> output = np.repeat(x, 2)
>>> print(output)
[1 vpn梯子 免费 1 2 2 3 3 4 4]
>>> output = 免费的vpn梯子 np.repeat(x, 3, axis=1)
>>> print(output)
[[1 vpn梯子 免费 1 1 2 vpn free 2 2]
[3 3 vpn梯子 免费 3 4 4 4]]
>>> output = np.repeat(x, [1, 2], axis=0)
>>> print(output)
[[1 2]
[3 4]
[3 4]]