Numpy flatten()
function is used to transform a multi-dimensional Numpy array to one-dimensional Numpy array. It always allocates new memory for the flattened array.
ndarray.flatten()
import numpy as np a = np.array([[23, 76, 11, 42], [74, 91, 8, 34]]) print(a.flatten())
Output of the above program
[23 76 11 42 74 91 8 34]
Let's understand how flatten() function works with a simple diagram. Diagram is in itself self-explanatory-