QR Decomposition
$$A = Q*R$$
While the LU decomposition is limited with square matrices, $QR$ decomposition does not have this limitation. In the QR decomposition, we factor a matrix to return a matrix $Q$ and $R$ where:
1. $Q$ is an othorgonal matrix:
$$Q*Q^T = I $$ and $$ Q=Q^{-1}$$
2. $R$ is Upper triangular matrix.
Implementation in Numpy
Performing QR decomposition in numpy can be done using the $qr()$ method which takes in a matrix.
import numpy as np
A = np.array(np.linspace(1, 12, 12)).reshape(4,3)
A
Q,R = np.linalg.qr(A)
Q
R
Using the dot product to combine the factors, we get:
Q.dot(R)