Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-107

Flatten Matrix

Problem

Flatten matrix A into a single list in row-major order.

Rows are concatenated from top to bottom, and entries within a row from left to right.

Hint

A double comprehension over rows and then entries gives row-major order.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: [1,2,3,4]
case 2
in: [[[1,2,3]]]
expected: [1,2,3]
case 3
in: [[[1],[2],[3]]]
expected: [1,2,3]
case 4
in: [[[5]]]
expected: [5]
Starter codePython
def flatten_matrix(A):
    # Your code here
    pass

4 test cases · run your code against them in the editor