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