dpnp.linalg.qr
- dpnp.linalg.qr(a, mode='reduced')[source]
Compute the qr factorization of a matrix.
Factor the matrix a as qr, where q is orthonormal and r is upper-triangular.
For full documentation refer to
numpy.linalg.qr
.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- The input array with the dimensionality of at least 2.
mode ({"reduced", "complete", "r", "raw"}, optional) --
If K = min(M, N), then
"reduced" : returns Q, R with dimensions (…, M, K), (…, K, N)
"complete" : returns Q, R with dimensions (…, M, M), (…, M, N)
"r" : returns R only with dimensions (…, K, N)
"raw" : returns h, tau with dimensions (…, N, M), (…, K,)
Default:
"reduced"
.
- Returns:
When mode is "reduced" or "complete", the result will be a namedtuple with
the attributes Q and R.
Q (dpnp.ndarray) -- A matrix with orthonormal columns. When mode = "complete" the result is an orthogonal/unitary matrix depending on whether or not a is real/complex. The determinant may be either +/- 1 in that case. In case the number of dimensions in the input array is greater than 2 then a stack of the matrices with above properties is returned.
R (dpnp.ndarray) -- The upper-triangular matrix or a stack of upper-triangular matrices if the number of dimensions in the input array is greater than 2.
(h, tau) (tuple of dpnp.ndarray) -- The h array contains the Householder reflectors that generate Q along with R. The tau array contains scaling factors for the reflectors.
Examples
>>> import dpnp as np >>> a = np.random.randn(9, 6) >>> Q, R = np.linalg.qr(a) >>> np.allclose(a, np.dot(Q, R)) # a does equal QR array([ True]) >>> R2 = np.linalg.qr(a, mode='r') >>> np.allclose(R, R2) # mode='r' returns the same R as mode='full' array([ True]) >>> a = np.random.normal(size=(3, 2, 2)) # Stack of 2 x 2 matrices as input >>> Q, R = np.linalg.qr(a) >>> Q.shape (3, 2, 2) >>> R.shape (3, 2, 2) >>> np.allclose(a, np.matmul(Q, R)) array([ True])