Splitting the array is the reverse of joining. Now below is the complete reference for Numpy array splitting.

Splits an array into multiple sub-arrays along a specified axis.`np.split()`

:

import numpy as np arr = np.array([1, 2, 3, 4, 5, 6]) result = np.split(arr, 3) print(result) # Output: [array([1, 2]), array([3, 4]), array([5, 6])]

Splits an array horizontally (column-wise) into multiple sub-arrays.`np.hsplit()`

:

import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) result = np.hsplit(arr, 3) print(result) # Output: [array([[1], [4]]), array([[2], [5]]), array([[3], [6]])]

Splits an array vertically (row-wise) into multiple sub-arrays.`np.vsplit()`

:

import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) result = np.vsplit(arr, 2) print(result) # Output: [array([[1, 2, 3]]), array([[4, 5, 6]])]

Splits an array into multiple sub-arrays along a specified axis. Allows for uneven division of the array.`np.array_split()`

:

import numpy as np arr = np.array([1, 2, 3, 4, 5, 6]) result = np.array_split(arr, 4) print(result) # Output: [array([1, 2]), array([3, 4]), array([5]), array([6])]

Splits an array along the third dimension (depth) into multiple sub-arrays.`np.dsplit()`

:

import numpy as np arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) result = np.dsplit(arr, 2) print(result) # Output: [array([[[1], # [3]], # [[5], # [7]]]), array([[[2], # [4]], # [[6], # [8]]])]

Certainly! Here are a few more options for splitting arrays in NumPy:

Splits an array into multiple sub-arrays based on custom indices along a specified axis.`np.split()`

with custom indices:

import numpy as np arr = np.array([1, 2, 3, 4, 5, 6]) result = np.split(arr, [2, 4]) print(result) # Output: [array([1, 2]), array([3, 4]), array([5, 6])]

In this example, the `np.split()`

function is used to split `arr`

into sub-arrays at indices 2 and 4 along the first dimension.

** np.split():** Splits a 2D array into multiple sub-arrays along a specified axis.

import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) result = np.split(arr, 3) print(result) # Output: [array([[1, 2, 3]]), array([[4, 5, 6]]), array([[7, 8, 9]])]

In this example, the `np.split()`

function is used to split the 2D array `arr`

into three sub-arrays along the first dimension.

Splits an array horizontally (column-wise) into multiple sub-arrays based on custom indices.`np.hsplit()`

with custom indices:

import numpy as np arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) result = np.hsplit(arr, [2]) print(result) # Output: [array([[1, 2], # [5, 6]]), array([[3, 4], # [7, 8]])]

In this example, the `np.hsplit()`

function is used to split `arr`

into sub-arrays at index 2 along the second dimension.

import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) result = np.hsplit(arr, 3) print(result) # Output: [array([[1], [4], [7]]), array([[2], [5], [8]]), array([[3], [6], [9]])]

In this example, the `np.hsplit()`

function splits the 2D array `arr`

into three sub-arrays along the second dimension.

Splits an array vertically (row-wise) into multiple sub-arrays based on custom indices.`np.vsplit()`

with custom indices:

import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) result = np.vsplit(arr, [1, 2]) print(result) # Output: [array([[1, 2, 3]]), array([[4, 5, 6]]), array([[7, 8, 9]])]

In this example, the `np.vsplit()`

function is used to split `arr`

into sub-arrays at indices 1 and 2 along the first dimension.

import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) result = np.vsplit(arr, 3) print(result) # Output: [array([[1, 2, 3]]), array([[4, 5, 6]]), array([[7, 8, 9]])]

The `np.vsplit()`

function splits the 2D array `arr`

into three sub-arrays along the first dimension, producing the same result as `np.split()`

in this case.

Splits an array into multiple sub-arrays based on custom indices along a specified axis. Allows for uneven division of the array.`np.array_split()`

with custom indices:

import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7]) result = np.array_split(arr, [3, 5]) print(result) # Output: [array([1, 2, 3]), array([4, 5]), array([6, 7])]

In this example, the `np.array_split()`

a function is used to split `arr`

into sub-arrays at indices 3 and 5 along the first dimension.

import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) result = np.array_split(arr, 2, axis=0) print(result) # Output: [array([[1, 2, 3], [4, 5, 6]]), array([[7, 8, 9]])]

In this example, the `np.array_split()`

function is used to split the 2D array `arr`

into two sub-arrays along the first dimension.

#### Run Code In Live & Test

#### Conclusion:

These are the main functions in NumPy for splitting arrays. allowing you to specify custom indices for splitting along different dimensions or axes. You can adapt these methods based on your specific requirements for dividing arrays into smaller sub-arrays. Each function provides different ways to split arrays along different dimensions or axes, allowing you to divide arrays into smaller sub-arrays for further processing or analysis.