Overview
The matrix inverse of a matrix A, is a matrix that when multiplied by A returns the identity matrix. That is, the following holds
{% A^{-1} A = I %}
When the matrix A multiplies a vector, it returns another vector.
{% A \vec{x} = \vec{b} %}
Then the original vector can be recovered from b by multiplying it by the matrix inverse of A.
{% \vec{x} = A^{-1} \vec{b} %}
This works for matrices that have an inverse. (square with determinant not equal to zero)
Properties
{% \vec{x} = (A^T A)^{-1}A^T \vec{b} %}
Implmentation
import numpy as np
# Create a sample rectangular matrix (3x2)
A = np.array([[1, 2],
[3, 4],
[5, 6]])
# Compute the pseudo-inverse
A_pinv = np.linalg.pinv(A)
print("Original Matrix A:\n", A)
print("\nPseudo-inverse A⁺:\n", A_pinv)