It is used to split arrays into multiple sub-arrays column-wise (horizontally).
Syntax:
numpy.hsplit(array, sections)
Example:
For 1-D Array:
import numpy as np
a=np.arange(6)
b=np.hsplit(a,2)
print(b)
Output:
[array([0, 1, 2]), array([3, 4, 5])]
For 2-D Array:
import numpy as np
a=np.array([[1,2],[3,4],[5,6],[7,8]])
b=np.hsplit(a,2)
print(b)
Output:
[array([[1], [3], [5], [7]]), array([[2], [4], [6], [8]])]
Note: hsplit()
isĀ alternate to hstack()
.