[SciPy-user] RREF - upper triangular

Robert Kern robert.kern at gmail.com
Sat Feb 18 16:49:57 EST 2006


Ryan Krauss wrote:
> Is there a scipy function to find the upper triangular form of a
> matrix?  I need to find the null space or null spaces of a matrix and
> have messed around with SVD in the past, but it seems like doing row
> reduction on something like [A]x=[0] has worked well.  I have written
> my own RREF algorithm in Python, but it seems like I have re-invented
> the wheel and I would prefer to use something someone else already
> wrote who is smarter about round-off error and I would also prefer
> something in FORTRAN of C for speed.  It seems like linalg.solve
> almost does what I want except I would need it to return the matrix I
> assume it is calculating instead of or along with the solution.

Well, there's rank-revealing QR, which does essentially what you want. The
appropriate LAPACK functions are xGEQP3. It is not currently wrapped in
scipy.linalg, but it should be fairly easy to add.

The LU and (regular) QR decompositions won't help you because they don't do any
ordering to demonstrate the rank. RRQR will order R, the upper-triangular
matrix, such that R[rank(A):,:] are all 0.

-- 
Robert Kern
robert.kern at gmail.com

"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