# jax.scipy.linalg.qrÂ¶

jax.scipy.linalg.qr(a, overwrite_a=False, lwork=None, mode='full', pivoting=False, check_finite=True)[source]Â¶

Compute QR decomposition of a matrix.

LAX-backend implementation of qr(). Original docstring below.

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

Parameters
• a ((M, N) array_like) â€“ Matrix to be decomposed

• overwrite_a (bool, optional) â€“ Whether data in a is overwritten (may improve performance)

• lwork (int, optional) â€“ Work array size, lwork >= a.shape[1]. If None or -1, an optimal size is computed.

• mode ({'full', 'r', 'economic', 'raw'}, optional) â€“ Determines what information is to be returned: either both Q and R (â€˜fullâ€™, default), only R (â€˜râ€™) or both Q and R but computed in economy-size (â€˜economicâ€™, see Notes). The final option â€˜rawâ€™ (added in SciPy 0.11) makes the function return two matrices (Q, TAU) in the internal format used by LAPACK.

• pivoting (bool, optional) â€“ Whether or not factorization should include pivoting for rank-revealing qr decomposition. If pivoting, compute the decomposition A P = Q R as above, but where P is chosen such that the diagonal of R is non-increasing.

• check_finite (bool, optional) â€“ Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.

Returns

• Q (float or complex ndarray) â€“ Of shape (M, M), or (M, K) for mode='economic'. Not returned if mode='r'.

• R (float or complex ndarray) â€“ Of shape (M, N), or (K, N) for mode='economic'. K = min(M, N).

• P (int ndarray) â€“ Of shape (N,) for pivoting=True. Not returned if pivoting=False.

Raises

LinAlgError â€“ Raised if decomposition fails

Notes

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

If mode=economic, the shapes of Q and R are (M, K) and (K, N) instead of (M,M) and (M,N), with K=min(M,N).

Examples

>>> from scipy import linalg
>>> a = np.random.randn(9, 6)

>>> q, r = linalg.qr(a)
>>> np.allclose(a, np.dot(q, r))
True
>>> q.shape, r.shape
((9, 9), (9, 6))

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

>>> q3, r3 = linalg.qr(a, mode='economic')
>>> q3.shape, r3.shape
((9, 6), (6, 6))

>>> q4, r4, p4 = linalg.qr(a, pivoting=True)
>>> d = np.abs(np.diag(r4))
>>> np.all(d[1:] <= d[:-1])
True
>>> np.allclose(a[:, p4], np.dot(q4, r4))
True
>>> q4.shape, r4.shape, p4.shape
((9, 9), (9, 6), (6,))

>>> q5, r5, p5 = linalg.qr(a, mode='economic', pivoting=True)
>>> q5.shape, r5.shape, p5.shape
((9, 6), (6, 6), (6,))