![]() |
VOOZH | about |
Flattening means converting a 2D matrix into a 1D array. In NumPy, this is done using the ndarray.flatten() function.
👁 FlattenMatrixThe flatten() function creates a copy of the array and returns it in 1D form.
Example 1: Flattening a 2×3 Matrix
[10 20 30 40 50 60]
The values are read row by row and stacked into a 1D array.
numpy_array.flatten(order='C')
Parameters:
Return: A new flattened 1D array.
Example 2: Flattening a 3×2 Matrix
[ 6 9 8 5 18 21]
Again, elements are read row by row and merged into 1D.
Example 3: Flatten with order Parameter
[ 6 9 12 8 5 2 18 21 24]
Here, since the array is stored in row-major order, the result is the same as 'C'.