Numpy array_split()

numpy.array_split(ary, indices_or_sections, axis=0)
Return broken array .
aryinput array to be broken
sectionsnumber, number of sections of output .

Examples

import numpy as np
my_ar=np.arange(9) 
print(np.array_split(my_ar,3))
Output
[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8])]
With unequal number of elements in output
my_ar=np.arange(9) 
print(np.array_split(my_ar,5))
Output
[array([0, 1]), array([2, 3]), array([4, 5]), array([6, 7]), array([8])]
Example
import numpy as np
my_ar=np.arange(9) 
print(np.array_split(my_ar,4))
Output
[array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
my_data=np.array([[6, 3, 2], [7, 2, 2], [6, 2, 9]])
print(np.array_split(my_data,3))
Output
[array([[6, 3, 2]]), array([[7, 2, 2]]), array([[6, 2, 9]])]
Elements of the output array
import numpy as np
my_data=np.array([[6, 3, 2], [7, 2, 2], [6, 2, 9]])
my_ar=np.array_split(my_data,3)
print(my_ar[1])    # [[7 2 2]]
print(my_ar[1][0]) #  [7 2 2]
print(my_ar[1][0][2]) # 2
Using float dtype
my_ar=np.arange(9.) 
print(np.array_split(my_ar,4))
Output
[array([0., 1., 2.]), array([3., 4.]), array([5., 6.]), array([7., 8.])]
Numpy eye() ones() bincount()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer