What is the numpy.linalg.matrix_rank() Method

Numpy.linalg.matrix_rank() method “returns matrix rank of an array using SVD method.”


numpy.linalg.matrix_rank(array, tol,  hermitian=False)


The matrix_rank() function takes mainly two parameters:

  1. array: This is the array whose rank we want to find.
  2. tol: Threshold below which SVD values are considered zero. If tol is None, S is an array with singular values for M, and eps is the epsilon value for the datatype of S, then tol is set to S.max() * max(M.shape) * eps.
  3. hermitian: Set to ‘False’ by default, it is used to specify whether the input matrix is Hermitian so as to deploy a more efficient technique for rank deduction

Return Value

The matrix_rank() function returns an integer value, which denotes the rank of the given Matrix.

Example 1: How does the np.linalg.matrix_rank() Method Work

from numpy import linalg as LA
import numpy as np

arr1 = np.array([4, 5, 0, 1])
print("Matrix rank of the 1st array is: ", LA.matrix_rank(arr1, 0))

arr2 = np.array(np.zeros(4))
print("The Matrix is: ", arr2)
print("Matrix rank of the 2nd array is: ", LA.matrix_rank(arr2, 0))


Matrix rank of the 1st array is: 1
The Matrix is: [0. 0. 0. 0.]
Matrix rank of the 2nd array is: 0

Example 2: How to Use np.linalg.matrix_rank() Method

from numpy import linalg as LA
import numpy as np

arr1 = np.array([[1, 2, 3], [6, 5, 4]])
print("The arr1 is :\n", arr1)
print("Matrix Rank is:\n", LA.matrix_rank(arr1, 1))

arr2 = np.array(np.zeros((4, 4)))
print("Arr2 is: \n: ", arr2)
print("Matrix Rank is:\n", LA.matrix_rank(arr2, 2))


The arr1 is :
 [[1 2 3]
 [6 5 4]]
Matrix Rank is:
Arr2 is:
: [[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]
Matrix Rank is:

That is it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.