mxnet.np.linalg.matrix_rank

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.

Notes

rtol param is requested in array-api-standard in https://data-apis.org/array-api/latest/extensions/generated/signatures.linalg.matrix_rank.html instead of a parameter in official NumPy operator.

Parameters
  • 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.

Returns

rank – Rank of M.

Return type

(..) ndarray

Examples

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