Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-038

Matrix Rank via Row Reduction

Problem

Compute the rank of a matrix A: the number of nonzero pivots after Gaussian elimination.

Use a tolerance of 1e-9 when deciding whether a pivot is nonzero.

Hint

Eliminate entries below each pivot, then count the pivots.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: 2
case 2
in: [[[1,2],[2,4]]]
expected: 1
case 3
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: 2
case 4
in: [[[0,0],[0,0]]]
expected: 0
Starter codePython
def matrix_rank(A):
    # Your code here
    pass

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