How to Split 2-D NumPy Arrays Along Rows


In this example, we will learn how to split the 2-D NumPy arrays along rows Using the Hsplit() 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.hsplit(n, 3)

print(split_n)

Output:

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