Compute QR decomposition of a matrix.
Calculate the decomposition where Q is orthonormal and R upper triangular.
Parameters: | a : array_like, shape (M, N)
mode : {‘full’, ‘r’, ‘economic’}
|
---|---|
Returns: | mode = ‘full’ : Q : double or complex array, shape (M, K) R : double or complex array, shape (K, N)
mode = ‘r’ : R : double or complex array, shape (K, N) mode = ‘economic’ : A2 : double or complex array, shape (M, N)
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