1、hsplit,水平方向分割。
array的数量通过指定返回相同的shape,或者分割应该发生后的列沿其横轴进行分割。
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]]] ''' #六分-自定义分割 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]]] '''
以上是python数组分割的函数,希望对大家有所帮助。更多Python学习指导:python基础教程