09-numpy-笔记-repeat
repeat:复制元素
axis = 0 复制每行
axis = 1 复制每列
2 表示复制一遍
不设置axis,复制每个,按行展开成一行。
>>> import numpy as np >>> a = np.mat([[1,2,3],[4,5,6]]) >>> a matrix([[1, 2, 3], [4, 5, 6]]) >>> a.repeat(2, axis = 0) matrix([[1, 2, 3], [1, 2, 3], [4, 5, 6], [4, 5, 6]]) >>> a.repeat(2, axis = 1) matrix([[1, 1, 2, 2, 3, 3], [4, 4, 5, 5, 6, 6]]) >>> a.repeat(2) matrix([[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]])