numpy.repeat(a, repeats, axis=None)

官方文档

Repeat elements of an array.

axis维度上切片,将数组a重复repeats

参数含义:

a:输入矩阵
repeats:元素重复的次数
axis:在哪个维度上进行切片,如果未指定,则对矩阵做flatten处理

示例:

>>> 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]])
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐