How to Split NumPy Arrays Using Array_split() Method


In this example we will show how to split the NumPy arrays using the array_split() method in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 4, 5, 6, 7, 8])

split_n_1 = np.array_split(n, 4)
print(split_n_1)

# adjust from the end accordingly
split_n_2 = np.array_split(n, 5)
print(split_n_2)

Output:

[array([1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
[array([1, 2]), array([3, 4]), array([5, 6]), array([7]), array([8])]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments