[SciPy-user] finding approximate rank of matrix

Robert Kern rkern at ucsd.edu
Wed Aug 3 23:58:36 CDT 2005


Dan Christensen wrote:
> Suppose you have 300 vectors each with 64 components, and you want to
> find the smallest subspace of R^64 that they all lie in.  That would
> just be the rank of the 300x64 matrix that they form.  But
> unfortunately the vectors are generated numerically to low precision
> (maybe 1e-5 relative error?).  So taken literally, they will span
> R^64.  I'd like to find the smallest subspace of R^64 that they all
> approximately lie in, with a specified tolerance.
> 
> Is there an easy way to do this?

To find the nullspace:

def null(A, eps=1e-16):
     u, s, vh = scipy.linalg.svd(A)
     mask = (s/s[0] <= eps)
     rowspace = scipy.compress(mask, vh, axis=0)
     return scipy.conjugate(scipy.transpose(rowspace))

Doing the converse to find the spanned subspace is an exercise left to 
the reader.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the SciPy-user mailing list