numpy中元素的重复numpy.repeat
numpy.repeat(a, repeats, axis=None)[source]官方文档a:输入矩阵repeats:元素重复的次数axis:在哪个axis上重复,如把每一行重复若干次就置axis=0,把每一列重复若干次就置axis=1示例>>> np.repeat(3, 4)array([3, 3, 3, 3])>>> x = np.array([[1,2
·
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]])
更多推荐
所有评论(0)