On 6/21/07, traveller3141 <traveller3141@gmail.com> wrote:
I'm in the process of trying to convert some Matlab code into Python. There's a statement of the form:

[q,r,e] = qr(A)

which performs a qr-decomposition of A, but then also returns a 'permutation' matrix. The purpose of this is to ensure that the values along r's diagonal are decreasing. I believe this technique is called "qr decomposition with column pivoting" or (equivalently) "qr decomposition with householder reflections".

There is a qr version in numpy, numpy.linalg.qr, but it only returns the factors q and r. The underlying lapack routines are {dz}geqrf and {dz}orgqr, the latter converting the product of Householder reflections into the orthogonal matrix q. Column pivoting is not used in {dz}geqrf, but it *is* used in {dz}geqpf.  The versions with column pivoting are probably more accurate and also allow fixing certain columns to the front of the array, a useful thing in some cases, so I don't know why we chose the first rather than the second. I suspect the decision was made in Numeric long ago and the simplest function was chosen. The column pivoting version isn't in scipy either and it probably should be. If you need it, it shouldn't be hard to add.