mxnet.np.linalg.qr¶
-
qr
(a, mode='reduced')¶ Compute the qr factorization of a matrix a. Factor the matrix a as qr, where q is orthonormal and r is upper-triangular.
- Parameters
a ((.., M, N) ndarray) – Matrix or stack of matrices to be qr factored.
mode ({‘reduced’, ‘complete’, ‘r’, ‘raw’, ‘full’, ‘economic’}, optional) – Only default mode, ‘reduced’, is implemented. If K = min(M, N), then * ‘reduced’ : returns q, r with dimensions (M, K), (K, N) (default)
- Returns
q ((…, M, K) ndarray) – A matrix or stack of matrices with K orthonormal columns, with K = min(M, N).
r ((…, K, N) ndarray) – A matrix or stack of upper triangular matrices.
- Raises
MXNetError – If factoring fails.
Notes
Currently, the gradient for the QR factorization is well-defined only when the first K columns of the input matrix are linearly independent.
Examples
>>> from mxnet import np >>> a = np.random.uniform(-10, 10, (2, 2)) >>> q, r = np.linalg.qr(a) >>> q array([[-0.22121978, -0.97522414], [-0.97522414, 0.22121954]]) >>> r array([[-4.4131265 , -7.1255064 ], [ 0. , -0.28771925]]) >>> a = np.random.uniform(-10, 10, (2, 3)) >>> q, r = np.linalg.qr(a) >>> q array([[-0.28376842, -0.9588929 ], [-0.9588929 , 0.28376836]]) >>> r array([[-7.242763 , -0.5673361 , -2.624416 ], [ 0. , -7.297918 , -0.15949416]]) >>> a = np.random.uniform(-10, 10, (3, 2)) >>> q, r = np.linalg.qr(a) >>> q array([[-0.34515655, 0.10919492], [ 0.14765628, -0.97452265], [-0.92685735, -0.19591334]]) >>> r array([[-8.453794, 8.4175 ], [ 0. , 5.430561]])