### Navigation

- index
- modules |
- next |
- previous |
- SciPy v0.7 Reference Guide (DRAFT) »
- Linear algebra (`scipy.linalg`) »

# scipy.linalg.qr

`scipy.linalg.``qr`(a, overwrite_a=0, lwork=None, econ=None, mode='qr')

  Compute QR decomposition of a matrix.

  Calculate the decomposition :lm:`A = Q R` where Q is unitary/orthogonal and R upper triangular.

  Parameters: | a : array, shape (M, N) Matrix to be decomposed overwrite_a : boolean Whether data in a is overwritten (may improve performance) lwork : integer Work array size, lwork >= a.shape[1]. If None or -1, an optimal size is computed. econ : boolean Whether to compute the economy-size QR decomposition, making shapes of Q and R (M, K) and (K, N) instead of (M,M) and (M,N). K=min(M,N). Default is False. mode : {‘qr’, ‘r’} Determines what information is to be returned: either both Q and R or only R.
  Returns: | (if mode == ‘qr’) : Q : double or complex array, shape (M, M) or (M, K) for econ==True (for any mode) : R : double or complex array, shape (M, N) or (K, N) for econ==True Size K = min(M, N) Raises LinAlgError if decomposition fails :

  Notes

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

  Examples

      >>> from scipy import random, linalg, dot
      >>> a = random.randn(9, 6)
      >>> q, r = linalg.qr(a)
      >>> allclose(a, dot(q, r))
      True
      >>> q.shape, r.shape
      ((9, 9), (9, 6))

      >>> r2 = linalg.qr(a, mode='r')
      >>> allclose(r, r2)

      >>> q3, r3 = linalg.qr(a, econ=True)
      >>> q3.shape, r3.shape
      ((9, 6), (6, 6))

### Navigation

- index
- modules |
- next |
- previous |
- SciPy v0.7 Reference Guide (DRAFT) »
- Linear algebra (`scipy.linalg`) »