numpy.hsplit


Advertisements

The numpy.hsplit is a special case of split() function where axis is 1 indicating a horizontal split regardless of the dimension of the input array.

Example

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'

Its output would be as follows −

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]])] 
numpy_array_manipulation.htm
Advertisements