The Wayback Machine - https://web.archive.org/web/20240119133040/https://www.geeksforgeeks.org/numpy-hsplit-function-python/
Open In App
Related Articles

numpy.hsplit() function | Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

numpy.hsplit() function split an array into multiple sub-arrays horizontally (column-wise). hsplit is equivalent to split with axis=1, the array is always split along the second axis regardless of the array dimension.

Syntax : numpy.hsplit(arr, indices_or_sections)
Parameters :
arr : [ndarray] Array to be divided into sub-arrays.
indices_or_sections : [int or 1-D array] If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis.
If indices_or_sections is a 1-D array of sorted integers, the entries indicate where along axis the array is split
Return : [ndarray] A list of sub-arrays.

Code #1 :




# Python program explaining
# numpy.hsplit() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.arange(16.0).reshape(4, 4)
  
gfg = geek.hsplit(arr, 2)
  
print (gfg)


Output :

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

 
Code #2 :




# Python program explaining
# numpy.hsplit() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.arange(27.0).reshape(3, 3, 3)
  
gfg = geek.hsplit(arr, 1)
  
print (gfg)


Output :

[array([[[  0.,   1.,   2.],
        [  3.,   4.,   5.],
        [  6.,   7.,   8.]],

       [[  9.,  10.,  11.],
        [ 12.,  13.,  14.],
        [ 15.,  16.,  17.]],

       [[ 18.,  19.,  20.],
        [ 21.,  22.,  23.],
        [ 24.,  25.,  26.]]])]
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials