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 `tol`. .. versionchanged:: 1.14 Can now operate on stacks of matrices Parameters ---------- A : {(M,), (..., M, N)} array_like
(A, tol=None, hermitian=False)
| 1824 | |
| 1825 | @array_function_dispatch(_matrix_rank_dispatcher) |
| 1826 | def matrix_rank(A, tol=None, hermitian=False): |
| 1827 | """ |
| 1828 | Return matrix rank of array using SVD method |
| 1829 | |
| 1830 | Rank of the array is the number of singular values of the array that are |
| 1831 | greater than `tol`. |
| 1832 | |
| 1833 | .. versionchanged:: 1.14 |
| 1834 | Can now operate on stacks of matrices |
| 1835 | |
| 1836 | Parameters |
| 1837 | ---------- |
| 1838 | A : {(M,), (..., M, N)} array_like |
| 1839 | Input vector or stack of matrices. |
| 1840 | tol : (...) array_like, float, optional |
| 1841 | Threshold below which SVD values are considered zero. If `tol` is |
| 1842 | None, and ``S`` is an array with singular values for `M`, and |
| 1843 | ``eps`` is the epsilon value for datatype of ``S``, then `tol` is |
| 1844 | set to ``S.max() * max(M, N) * eps``. |
| 1845 | |
| 1846 | .. versionchanged:: 1.14 |
| 1847 | Broadcasted against the stack of matrices |
| 1848 | hermitian : bool, optional |
| 1849 | If True, `A` is assumed to be Hermitian (symmetric if real-valued), |
| 1850 | enabling a more efficient method for finding singular values. |
| 1851 | Defaults to False. |
| 1852 | |
| 1853 | .. versionadded:: 1.14 |
| 1854 | |
| 1855 | Returns |
| 1856 | ------- |
| 1857 | rank : (...) array_like |
| 1858 | Rank of A. |
| 1859 | |
| 1860 | Notes |
| 1861 | ----- |
| 1862 | The default threshold to detect rank deficiency is a test on the magnitude |
| 1863 | of the singular values of `A`. By default, we identify singular values less |
| 1864 | than ``S.max() * max(M, N) * eps`` as indicating rank deficiency (with |
| 1865 | the symbols defined above). This is the algorithm MATLAB uses [1]. It also |
| 1866 | appears in *Numerical recipes* in the discussion of SVD solutions for linear |
| 1867 | least squares [2]. |
| 1868 | |
| 1869 | This default threshold is designed to detect rank deficiency accounting for |
| 1870 | the numerical errors of the SVD computation. Imagine that there is a column |
| 1871 | in `A` that is an exact (in floating point) linear combination of other |
| 1872 | columns in `A`. Computing the SVD on `A` will not produce a singular value |
| 1873 | exactly equal to 0 in general: any difference of the smallest SVD value from |
| 1874 | 0 will be caused by numerical imprecision in the calculation of the SVD. |
| 1875 | Our threshold for small SVD values takes this numerical imprecision into |
| 1876 | account, and the default threshold will detect such numerical rank |
| 1877 | deficiency. The threshold may declare a matrix `A` rank deficient even if |
| 1878 | the linear combination of some columns of `A` is not exactly equal to |
| 1879 | another column of `A` but only numerically very close to another column of |
| 1880 | `A`. |
| 1881 | |
| 1882 | We chose our default threshold because it is in wide use. Other thresholds |
| 1883 | are possible. For example, elsewhere in the 2007 edition of *Numerical |