1、hsplit,水平方向分割。
通过指定返回相同shape的array的数量,或者分割应该发生之后的列来沿着其横轴拆分。
2、vsplit,沿着垂直轴分割。
3、split/array_split,自定义分割,axis=1 水平分割,axis=0 垂直方向分割。
实例
#4.分割-水平方向分割 h5=np.random.randint(0,100,size=(6,4)) h5 '''array([[13,7,29,65], [57,50,79,12], [9,16,82,86], [97,62,43,92], [66,21,78,34], [95,33,51,63]])''' np.hsplit(h5,2)#将h5水平分割等分两个数组,被分割的列一定为指定分割数的倍数 '''[array([[13,7], [57,50], [9,16], [97,62], [66,21], [95,33]]), array([[29,65], [79,12], [82,86], [43,92], [78,34], [51,63]])]''' np.hsplit(h5,[1,3])#将h5从下标为1、3的地方水平分割 '''[array([[13], [57], [9], [97], [66], [95]]), array([[7,29], [50,79], [16,82], [62,43], [21,78], [33,51]]), array([[65], [12], [86], [92], [34], [63]])] ''' #5分割-纵向分割 np.vsplit(h5,3) ''' [array([[13,7,29,65], [57,50,79,12]]), array([[9,16,82,86], [97,62,43,92]]), array([[66,21,78,34], [95,33,51,63]])] ''' np.vsplit(h5,[1,2]) ''' [array([[13,7,29,65]]), array([[57,50,79,12]]), array([[9,16,82,86], [97,62,43,92], [66,21,78,34], [95,33,51,63]])] ''' #6分割-自定义分割 np.split(h5,2,axis=1)#横向分割,按列分割 ''' [array([[13,7], [57,50], [9,16], [97,62], [66,21], [95,33]]), array([[29,65], [79,12], [82,86], [43,92], [78,34], [51,63]])] ''' np.split(h5,3,axis=0)#纵向分割,按行分割 ''' [array([[13,7,29,65], [57,50,79,12]]), array([[9,16,82,86], [97,62,43,92]]), array([[66,21,78,34], [95,33,51,63]])] '''