How to Convert 1-D NumPy Array Into 2-D


In this example, we will learn how to convert the 1-D NumPy array into a 2-D NumPy array in Python.

Source Code

import numpy as np

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

reshape_n = n.reshape(2, 4)

print(reshape_n)

Output:

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