$LU$ Matrix Decomposition
The $LU$ decomposition factorizes a matrix into the Lower and Upper Triangular Matrices which are simpler forms of matrices. LU decomposition is performed on square matrices $nxn$
Mathematical notation for LU decomposition of a matrix $A$ is
$$ A = L * U $$
Recall the Lower Triangle Matrix is a matrix with who values above the diagonal are set to zero and those below are non-zero. An Upper triangle matrix is the exact opposite.
PLU Decomposition
Sometimes the LU decomposition may not be feasible. A useful variation of this type of decomposition is the PLU, Permutation, Lower Triangle and Upper Triangle decomposition. The permutation matrix provides a neat dimension to resolve the results of $L$ and $U$ to its orinal state.
PLU decomposition takes the form:
$$ PLU = P*L*U$$
Implementation in Numpy and scipy
import numpy as np
from scipy.linalg import lu
A = np.array(np.linspace(1,9, 9)).reshape(3,3)
A
Running the PLU decomposition
P,L,U = lu(A)
P
Returning the Lower Triangle
L
Returning the upper triangle
U
Combining all the matrices together in a dot product, we get:
P.dot(L).dot(U)