The ndarray.flatten() method in Python is used to return a copy of a given array in such a way that it is collapsed into one dimension.
ndarray.flatten(order='C')
The ndarray.flatten() method takes an optional parameter value, orfer, which represents the order to which the array is to be flattened. The different orders are:
'C': This is to flatten the array in row-major order.'F': This is to flatten the array in column-major order.'A': This is to flatten the array in column-major order, if the input array is Fortran contiguous in memory, and row-major order if otherwise.'K': This is to flatten the array in the order in which its elements occur in memory.The default value is 'C'.
import numpy as np# creating an input arraymyarray = np.array([[1,2,3],[4,5,6]])# to flatten the array in F-orderprint(myarray.flatten('F'))
numpy module.myarray , using the array() function.ndarray.flatten() method on the input array. We print the result to the console.