Added mat_flat module utility file
This commit is contained in:
parent
ccacab51ea
commit
7dd801985e
19
mat_flat.py
Normal file
19
mat_flat.py
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
from typing import List
|
||||
"""
|
||||
Flattens a 2D list (matrix) into a 1D list.
|
||||
Args:
|
||||
M (List[List]): A two-dimensional list to be flattened.
|
||||
Returns:
|
||||
List: A one-dimensional list containing all elements of the input matrix in row-major order.
|
||||
Example:
|
||||
>>> flatten([[1, 2], [3, 4]])
|
||||
[1, 2, 3, 4]
|
||||
|
||||
NOTE: If you add the mat_flat module to a project, call it with mat_flat.flatten(M).
|
||||
|
||||
"""
|
||||
|
||||
def flatten(M: List[List])-> List:
|
||||
flat = [elem for row in M for elem in row]
|
||||
return flat
|
||||
Loading…
Reference in New Issue
Block a user