How to Split 2-D NumPy Arrays Along Columns


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

Source Code

import numpy as np

n = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]])

split_n = np.array_split(n, 3)

print(split_n)

Output:

[array([[1, 2, 3],
       [4, 5, 6]]), array([[ 7,  8,  9],
       [10, 11, 12]]), array([[13, 14, 15]])]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments