numpy.hsplit


numpy.hsplit是split()函数的一个特例,其中axis为1表示水平分割,与输入数组的维度无关。

import numpy as np
a = np.arange(16).reshape(4,4)

print 'First array:'
print a
print '\n'  

print 'Horizontal splitting:'
b = np.hsplit(a,2)
print b
print '\n'

其输出如下

First array:
[[ 0 1 2 3]
 [ 4 5 6 7]
 [ 8 9 10 11]
 [12 13 14 15]]

Horizontal splitting:                                                         
[array([[ 0,  1],                                                             
       [ 4,  5],                                                              
       [ 8,  9],                                                              
       [12, 13]]), array([[ 2,  3],                                           
       [ 6,  7],                                                              
       [10, 11],                                                              
       [14, 15]])]