# [Numpy-discussion] matrix rank of numpy array or matrix

mark markbak@gmail....
Tue Feb 5 13:37:12 CST 2008

```Thanks.
I rewrote the line as:

from numpy.linalg import svd
from numpy import sum,where

def matrixrank(A,tol=1e-8):
s = svd(A,compute_uv=0)
return sum( where( s>tol, 1, 0 ) )

Would be nice to include matrixrank in numpy, as it is really useful,

Thanks again, Mark

On Feb 5, 7:59 pm, "Nils Wagner" <nwag...@iam.uni-stuttgart.de> wrote:
> On Tue, 5 Feb 2008 10:54:01 -0800 (PST)
>   mark <mark...@gmail.com> wrote:
>
>
>
> > Hello -
>
> > Is there a function to compute the matrix rank of a
> >numpy array or
> > matrix?
> > So I don't mean the current rank(), which gives the
> >number of
> > dimensions.
> > I mean the number of independent equations of a matrix.
>
> > Thanks,
>
> > Mark
> > _______________________________________________
> > Numpy-discussion mailing list
> > Numpy-discuss...@scipy.org
> >http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
> AFAIK, a build-in function is (still) missing.
> However you might use a singular value decomposition
> to compute the numerical rank of a matrix.
>
> See e.g.http://osdir.com/ml/python.numeric.general/2006-02/msg00154.html
>
> Nils
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss...@scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion
```