- paddle.linalg. matrix_rank ( x, tol=None, hermitian=False, name=None )
Computes the rank of a matrix.
The rank of a matrix is the number of singular values that are greater than the specified tol threshold when hermitian=False, or the number of eigenvalues in absolute value that are greater than the specified tol threshold when hermitian=True.
x (Tensor) – The input tensor. Its shape should be […, m, n], where … is zero or more batch dimensions. If x is a batch of matrices then the output has the same batch dimensions. The data type of x should be float32 or float64.
tol (float,Tensor,optional) – the tolerance value. Default: None. If tol is not specified, and sigma is the largest singular value (or eigenvalues in absolute value), and eps is the epsilon value for the dtype of x, then tol is computed with formula tol=sigma * max(m,n) * eps. Note that if x is a batch of matrices, tol is computed this way for every batch.
hermitian (bool,optional) – indicates whether x is Hermitian. Default: False. When hermitian=True, x is assumed to be Hermitian, enabling a more efficient method for finding eigenvalues, but x is not checked inside the function. Instead, We just use the lower triangular of the matrix to compute.
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
Rank of tensor x.
- Return type
import paddle a = paddle.eye(10) b = paddle.linalg.matrix_rank(a) print(b) # b =  c = paddle.ones(shape=[3, 4, 5, 5]) d = paddle.linalg.matrix_rank(c, tol=0.01, hermitian=True) print(d) # d = [[1, 1, 1, 1], # [1, 1, 1, 1], # [1, 1, 1, 1]]