bundles / scipy 1.17.1 / scipy / linalg / _decomp_qr / rq
function
scipy.linalg._decomp_qr:rq
source: /scipy/linalg/_decomp_qr.py :372
Signature
def rq ( a , overwrite_a = False , lwork = None , mode = full , check_finite = True ) Summary
Compute RQ decomposition of a matrix.
Extended Summary
Calculate the decomposition A = R Q where Q is unitary/orthogonal and R upper triangular.
The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details. Note that calls with zero-size batches are unsupported and will raise a ValueError.
Parameters
a: (M, N) array_likeMatrix to be decomposed
overwrite_a: bool, optionalWhether data in a is overwritten (may improve performance)
lwork: int, optionalWork array size, lwork >= a.shape[1]. If None or -1, an optimal size is computed.
mode: {'full', 'r', 'economic'}, optionalDetermines 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).
check_finite: bool, optionalWhether 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
R: float or complex ndarrayOf shape (M, N) or (M, K) for
mode='economic'.K = min(M, N).Q: float or complex ndarrayOf shape (N, N) or (K, N) for
mode='economic'. Not returned ifmode='r'.
Raises
: LinAlgErrorIf decomposition fails.
Notes
This is an interface to the LAPACK routines sgerqf, dgerqf, cgerqf, zgerqf, sorgrq, dorgrq, cungrq and zungrq.
If mode=economic, the shapes of Q and R are (K, N) and (M, K) instead of (N,N) and (M,N), with K=min(M,N).
Examples
import numpy as np from scipy import linalg rng = np.random.default_rng() a = rng.standard_normal((6, 9)) r, q = linalg.rq(a) np.allclose(a, r @ q) r.shape, q.shape r2 = linalg.rq(a, mode='r') np.allclose(r, r2) r3, q3 = linalg.rq(a, mode='economic') r3.shape, q3.shape✓
Aliases
-
scipy.linalg.rq