matrix_rank(M, rtol=None, hermitian=False)

Return matrix rank of array using SVD method

Rank of the array is the number of singular values of the array that are greater than rtol.


rtol param is requested in array-api-standard in instead of a parameter in official NumPy operator.

  • M ({(M,), (.., M, N)} ndarray) – Input vector or stack of matrices.

  • rtol ((..) ndarray, float, optional) – Threshold below which SVD values are considered zero. If rtol is None, and S is an array with singular values for M, and eps is the epsilon value for datatype of S, then rtol is set to S.max() * max(M.shape) * eps.

  • hermitian (bool, optional) – If True, M is assumed to be Hermitian (symmetric if real-valued), enabling a more efficient method for finding singular values. Default: False.


rank – Rank of M.

Return type

(..) ndarray


>>> from mxnet import np
>>> np.linalg.matrix_rank(np.eye(4)) # Full rank matrix
>>> I=np.eye(4); I[-1,-1] = 0. # rank deficient matrix
>>> np.linalg.matrix_rank(I)
>>> np.linalg.matrix_rank(np.ones((4,))) # 1 dimension - rank 1 unless all 0
>>> np.linalg.matrix_rank(np.zeros((4,)))