---
title: "How to use NumPy Splitting Array in python?"  
description: "How to use NumPy Splitting Array in python?"  
author: "Jk Malhotra"  
published: 2025-11-16  
updated: 2025-11-16  
canonical: https://www.mindstick.com/interview/34413/how-to-use-numpy-splitting-array-in-python  
category: "python"  
tags: ["python-3.4", "numpy"]  
reading_time: 3 minutes  

---

# How to use NumPy Splitting Array in python?

> [NumPy](https://www.mindstick.com/interview/34402/introduction-to-numpy) provides several ways to **split an array into multiple sub-arrays**, depending on how you want to divide it. The most commonly used functions are:

## 1. `np.split()`

Splits an array **into equal or specified sections** along an axis.

### Example 1: Split 1D array into equal parts

```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])]
```

### Example 2: Split at specific indices

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

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

## Output:

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

## 2. `np.array_split()`

Same as `np.split()`, but **allows unequal splits**, which is useful when the array size isn’t divisible.

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

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

## Output:

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

## 3. `np.hsplit()` — Split Horizontally (column-wise)

For **2D arrays**, splits by columns.

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

# Split into 2 equal parts horizontally
result = np.hsplit(arr, 2)
print(result)
```

## 4. `np.vsplit()` — Split Vertically (row-wise)

Splits along rows.

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

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

## 5. `np.dsplit()` — Split along depth (for 3D arrays)

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

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

## When to use which?

| Function | Used For |
| --- | --- |
| `np.split` | Equal splits OR specific indices |
| `np.array_split` | Unequal splits allowed |
| `np.hsplit` | Split by columns (2D) |
| `np.vsplit` | Split by rows (2D) |
| `np.dsplit` | Split 3D arrays along depth |

## Answers

### Answer by Jk Malhotra

> [NumPy](https://www.mindstick.com/interview/34402/introduction-to-numpy) provides several ways to **split an array into multiple sub-arrays**, depending on how you want to divide it. The most commonly used functions are:

## 1. `np.split()`

Splits an array **into equal or specified sections** along an axis.

### Example 1: Split 1D array into equal parts

```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])]
```

### Example 2: Split at specific indices

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

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

## Output:

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

## 2. `np.array_split()`

Same as `np.split()`, but **allows unequal splits**, which is useful when the array size isn’t divisible.

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

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

## Output:

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

## 3. `np.hsplit()` — Split Horizontally (column-wise)

For **2D arrays**, splits by columns.

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

# Split into 2 equal parts horizontally
result = np.hsplit(arr, 2)
print(result)
```

## 4. `np.vsplit()` — Split Vertically (row-wise)

Splits along rows.

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

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

## 5. `np.dsplit()` — Split along depth (for 3D arrays)

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

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

## When to use which?

| Function | Used For |
| --- | --- |
| `np.split` | Equal splits OR specific indices |
| `np.array_split` | Unequal splits allowed |
| `np.hsplit` | Split by columns (2D) |
| `np.vsplit` | Split by rows (2D) |
| `np.dsplit` | Split 3D arrays along depth |


---

Original Source: https://www.mindstick.com/interview/34413/how-to-use-numpy-splitting-array-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
