numpy.linalg.qr

numpy.linalg.qr(a, mode='full')

Compute QR decomposition of a matrix.

Calculate the decomposition A = Q R where Q is orthonormal and R upper triangular.

Parameters:

a : array_like, shape (M, N)

Matrix to be decomposed

mode : {‘full’, ‘r’, ‘economic’}

Determines what information is to be returned. ‘full’ is the default. Economic mode is slightly faster if only R is needed.

Returns:

mode = ‘full’ :

Q : double or complex array, shape (M, K)

R : double or complex array, shape (K, N)

Size K = min(M, N)

mode = ‘r’ :

R : double or complex array, shape (K, N)

mode = ‘economic’ :

A2 : double or complex array, shape (M, N)

The diagonal and the upper triangle of A2 contains R, while the rest of the matrix is undefined.

If a is a matrix, so are all the return values. :

Raises LinAlgError if decomposition fails :

Notes

This is an interface to the LAPACK routines dgeqrf, zgeqrf, dorgqr, and zungqr.

Examples

>>> a = np.random.randn(9, 6)
>>> q, r = np.linalg.qr(a)
>>> np.allclose(a, np.dot(q, r))
True
>>> r2 = np.linalg.qr(a, mode='r')
>>> r3 = np.linalg.qr(a, mode='economic')
>>> np.allclose(r, r2)
True
>>> np.allclose(r, np.triu(r3[:6,:6], k=0))
True

Previous topic

numpy.linalg.cholesky

Next topic

numpy.linalg.svd

This Page

Quick search