linear_algebra.src.rank_of_matrix

Calculate the rank of a matrix.

See: https://en.wikipedia.org/wiki/Rank_(linear_algebra)

Functions

rank_of_matrix(→ int)

Finds the rank of a matrix.

Module Contents

linear_algebra.src.rank_of_matrix.rank_of_matrix(matrix: list[list[int | float]]) int

Finds the rank of a matrix. Args:

matrix: The matrix as a list of lists.

Returns:

The rank of the matrix.

Example: >>> matrix1 = [[1, 2, 3], … [4, 5, 6], … [7, 8, 9]] >>> rank_of_matrix(matrix1) 2 >>> matrix2 = [[1, 0, 0], … [0, 1, 0], … [0, 0, 0]] >>> rank_of_matrix(matrix2) 2 >>> matrix3 = [[1, 2, 3, 4], … [5, 6, 7, 8], … [9, 10, 11, 12]] >>> rank_of_matrix(matrix3) 2 >>> rank_of_matrix([[2,3,-1,-1], … [1,-1,-2,4], … [3,1,3,-2], … [6,3,0,-7]]) 4 >>> rank_of_matrix([[2,1,-3,-6], … [3,-3,1,2], … [1,1,1,2]]) 3 >>> rank_of_matrix([[2,-1,0], … [1,3,4], … [4,1,-3]]) 3 >>> rank_of_matrix([[3,2,1], … [-6,-4,-2]]) 1 >>> rank_of_matrix([[],[]]) 0 >>> rank_of_matrix([[1]]) 1 >>> rank_of_matrix([[]]) 0