The hsplit()
function in NumPy is used to split an input array into multiple subarrays horizontally.
numpy.hsplit(array, indices_or_sections, axis=0)
The hsplit()
function takes the following parameter values:
array
: This is the input array to be split. This is a required parameter.indices_or_sections
: This is an integer representation of the number of sections of the array to be split. An error is raised if the number of splits specified is not possible.axis
: This is the axis along which the split is done. The hsplit()
function returns a list of subarrays of the input array.
import numpy as np# creating the input arrrayfirst_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])# splitting the input array into 3 sub-arraysmy_array = np.hsplit(first_array, 5)# printing the split arrayprint(my_array)
numpy
module.first_array
, using the array()
function.5
subarrays using the hsplit()
function. We assign the result to a variable my_array
.my_array
.