Rank is a very important concept when it comes to solving linear equations. The rank of a matrix represents the amount of information that is kept in the matrix. A lower rank means less information, and a higher rank means a high amount of information. Rank can be defined as the number of independent rows or columns of a matrix. The numpy.linalg subpackage provides the matrix_rank() function. The matrix_rank() function takes the matrix as input and returns the computed rank of the matrix. Let's see an example of the matrix_rank() function in the following code block:
# import required libraries
import numpy as np
from numpy.linalg import matrix_rank
# Create a matrix
mat=np.array([[5, 3, 1],[5, 3, 1],[1, 0, 5]])
# Compute rank of matrix
print("Matrix: \n", mat)
print("Rank:",matrix_rank(mat))
This results in the following output:
Matrix:
[[5 3 1]
[5 3 1]
[1 0 5]]
Rank: 2
In the preceding code block, the matrix_rank() function of numpy.linalg...