How to work NumPy Splitting Array?
How to work NumPy Splitting Array, explain with example.
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Anubhav Kumar
25-Nov-20251.
np.splitSplits an array into equal parts (unless you specify explicit indices).
1. Using
np.splitwith equal splitsOutput:
2. Using
np.splitwith index positionsYou can specify split positions:
Output:
Explanation:
[10,20][30,40][50,60]2.
np.array_split(more flexible)Unlike
np.split, it allows uneven splits.Output:
3. Splitting a 2D Array
Horizontal split (
hsplit) → split columnsOutput:
Vertical split (
vsplit) → split rowsOutput:
4. Depth split (
dsplit) → split along 3D depth axisSummary Table
np.split()np.array_split()np.hsplit()np.vsplit()np.dsplit()