Utilities for working with matrices
Return full-rank matrix whose column span is the same as X
Uses an SVD decomposition.
If the rank of X is known it can be specified by r – no check is made to ensure that this really is the rank of X.
Parameters : | X : array-like
r : None or int
|
---|---|
Returns : | fX : array
|
Return rank of matrix using SVD method
Rank of the array is the number of SVD singular values of the array that are greater than tol.
Parameters : | M : array-like
tol : {None, float}
|
---|
Notes
Golub and van Loan [R10] define “numerical rank deficiency” as using tol=eps*S[0] (where S[0] is the maximum singular value and thus the 2-norm of the matrix). This is one definition of rank deficiency, and the one we use here. When floating point roundoff is the main concern, then “numerical rank deficiency” is a reasonable choice. In some cases you may prefer other definitions. The most useful measure of the tolerance depends on the operations you intend to use on your matrix. For example, if your data come from uncertain measurements with uncertainties greater than floating point epsilon, choosing a tolerance near that uncertainty may be preferable. The tolerance may be absolute if the uncertainties are absolute rather than relative.
References
[R10] | (1, 2)
|
Baltimore: Johns Hopkins University Press, 1996.
Examples
>>> matrix_rank(np.eye(4)) # Full rank matrix
4
>>> I=np.eye(4); I[-1,-1] = 0. # rank deficient matrix
>>> matrix_rank(I)
3
>>> matrix_rank(np.zeros((4,4))) # All zeros - zero rank
0
>>> matrix_rank(np.ones((4,))) # 1 dimension - rank 1 unless all 0
1
>>> matrix_rank(np.zeros((4,)))
0
>>> matrix_rank([1]) # accepts array-like
1
Return element-wise reciprocal of array, setting X>=0 to 0
Return the reciprocal of an array, setting all entries less than or equal to 0 to 0. Therefore, it presumes that X should be positive in general.
Parameters : | X : array-like |
---|---|
Returns : | rX : array
|