numpy.array_split#

numpy.array_split(ary,indices_or_sections,axis=0)[source]#

Split an array into multiple sub-arrays.

Please refer to thesplit documentation. The only differencebetween these functions is thatarray_split allowsindices_or_sections to be an integer that doesnot equallydivide the axis. For an array of length l that should be splitinto n sections, it returns l % n sub-arrays of size l//n + 1and the rest of size l//n.

See also

split

Split array into multiple sub-arrays of equal size.

Examples

>>>importnumpyasnp>>>x=np.arange(8.0)>>>np.array_split(x,3)[array([0.,  1.,  2.]), array([3.,  4.,  5.]), array([6.,  7.])]
>>>x=np.arange(9)>>>np.array_split(x,4)[array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
On this page