How to Flatten a NumPy Array


In this example we will show how to flatten a NumPy array(convert a multidimensional array into a 1D array) in Python.

Source Code

import numpy as np

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

reshape_n = n.reshape(-1)

print(reshape_n)

Output:

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