---
title: "How to work NumPy Splitting Array?"  
description: "How to work NumPy Splitting Array?"  
author: "ICSM Computer"  
published: 2025-11-13  
updated: 2025-11-25  
canonical: https://www.mindstick.com/forum/161999/how-to-work-numpy-splitting-array  
category: "python"  
tags: ["python-3.4", "numpy"]  
reading_time: 2 minutes  

---

# How to work NumPy Splitting Array?

**How to work NumPy [Splitting Array](https://www.mindstick.com/interview/34413/how-to-use-numpy-splitting-array-in-python), [explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) with example.**

## Replies

### Reply by Anubhav Sharma

> [NumPy](https://www.mindstick.com/interview/34402/introduction-to-numpy) provides multiple functions to split an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) into multiple sub-arrays:

## 1. `np.split`

Splits an array into **equal** parts (unless you specify explicit indices).

#### 1. Using `np.split` with equal splits

```python
import numpy as np

arr = np.array([1,2,3,4,5,6])

result = np.split(arr, 3)
print(result)
```

## Output:

```plaintext
[array([1, 2]), array([3, 4]), array([5, 6])]
```

- Here we split into **3 equal parts**, so each part contains 2 elements.
- If the array **cannot be split equally**, NumPy throws an error.

#### 2. Using `np.split` with index positions

You can specify **split positions**:

```python
arr = np.array([10, 20, 30, 40, 50, 60])

result = np.split(arr, [2, 4])
print(result)
```

## Output:

```plaintext
[array([10, 20]), array([30, 40]), array([50, 60])]
```

Explanation:

- Split at index 2 → `[10,20]`
- Split at index 4 → `[30,40]`
- Remaining → `[50,60]`

## 2. `np.array_split` (more flexible)

Unlike `np.split`, **it allows uneven splits**.

```python
arr = np.array([1,2,3,4,5,6,7])

result = np.array_split(arr, 3)
print(result)
```

## Output:

```plaintext
[array([1, 2, 3]), array([4, 5]), array([6, 7])]
```

## 3. Splitting a 2D Array

### Horizontal split (`hsplit`) → split columns

```python
arr = np.array([[1,2,3],
                [4,5,6]])

result = np.hsplit(arr, 3)
print(result)
```

## Output:

```plaintext
[array([[1],
       [4]]),
 array([[2],
       [5]]),
 array([[3],
       [6]])]
```

### Vertical split (`vsplit`) → split rows

```python
arr = np.array([[1,2,3],
                [4,5,6],
                [7,8,9]])

result = np.vsplit(arr, 3)
print(result)
```

## Output:

```plaintext
[array([[1, 2, 3]]),
 array([[4, 5, 6]]),
 array([[7, 8, 9]])]
```

## 4. Depth split (`dsplit`) → split along 3D depth axis

```python
arr = np.arange(12).reshape(2,2,3)

print(np.dsplit(arr, 3))
```

## Summary Table

| Function | Use |
| --- | --- |
| `np.split()` | Strict equal splits or split by index |
| `np.array_split()` | Allows uneven splits |
| `np.hsplit()` | Split columns |
| `np.vsplit()` | Split rows |
| `np.dsplit()` | Split along the depth of a 3D array |


---

Original Source: https://www.mindstick.com/forum/161999/how-to-work-numpy-splitting-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
