numpy.repeat

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

重复数组元素。

参数
aarray_like

输入数组。

repeatsint或int数组

每个元素的重复次数。 repeats 广播以适应给定轴的形状。

axis可选的

重复值的轴。默认情况下,使用扁平输入数组,并返回扁平输出数组。

返回
repeated_array恩达雷

与具有相同形状的输出数组 a ,沿给定轴除外。

参见

tile

平铺一个数组。

unique

查找数组的唯一元素。

实例

>>> np.repeat(3, 4)
array([3, 3, 3, 3])
>>> x = np.array([[1,2],[3,4]])
>>> np.repeat(x, 2)
array([1, 1, 2, 2, 3, 3, 4, 4])
>>> np.repeat(x, 3, axis=1)
array([[1, 1, 1, 2, 2, 2],
       [3, 3, 3, 4, 4, 4]])
>>> np.repeat(x, [1, 2], axis=0)
array([[1, 2],
       [3, 4],
       [3, 4]])