numpy.array_split — NumPy v2.6.dev0 Manual

Learn | NEPs | User Guide | API reference | Building from source | Development | Release notes | NumPy’s module structure | Array objects | Universal functions (ufunc) | Routines and objects by topic | Constants | Bit-wise operations | String functionality | Data type routines | Floating point error handling | Discrete Fourier Transform | Input and output | Linear algebra | Logic functions | Masked array operations | Mathematical functions | Miscellaneous routines | Random sampling | Set routines | Sorting, searching, and counting | Test support | Window functions

numpy.array_split(ary, indices_or_sections, axis=0)

[source]

#

Split an array into multiple sub-arrays.

Please refer to the split documentation. The only difference between these functions is that array_split allows indices_or_sections to be an integer that does not equally divide the axis. For an array of length l that should be split into n sections, it returns l % n sub-arrays of size l//n + 1 and 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])]

1 1