The Matrix Version of One
Just as for scalars, the identity matrix has ones on its main diagonal and zeros elsewhere, giving whenever the shapes match. It represents a transformation that changes nothing.
Transformations That Can Be Undone
For a square matrix , an inverse satisfies . A 30-degree rotation is undone by a -30-degree rotation, and uniform doubling is undone by halving. A two-sided inverse exists exactly when the square matrix has full rank, equivalently in exact mathematics. If a direction is collapsed, distinct inputs share an output and cannot be uniquely recovered.
Rectangular Matrices and the Pseudoinverse
A rectangular matrix has no two-sided inverse of the square-matrix kind. It does not always discard information, however: a full-column-rank map into a higher-dimensional space can preserve distinct inputs and may have a left inverse. A dimension-reducing map generally merges inputs.
The Moore-Penrose pseudoinverse handles these cases in a common framework. For an overdetermined system it can select a least-squares solution; when several solutions exist, it can select the minimum-norm one. It is not a promise to reconstruct information that the original transformation discarded.
In Code, Solve the System Directly
Although is a useful conceptual identity, use np.linalg.solve(A, B) for a square system instead of forming the inverse first. It is generally faster and more numerically stable. For rectangular problems, use a method such as lstsq that matches the question being asked.
import numpy as np
A = np.array([[2., 0.], [0., 2.]]) Ainv = np.linalg.inv(A)
print('Ainv =') print(Ainv)
v = np.array([10., 8.]) print('Ainv @ v =', Ainv @ v) print('v / 2 =', v / 2)
S = np.array([[1., 2.], [1., 2.]]) try: np.linalg.inv(S) except Exception as e: print(type(e).name, '->', e)
에러는 역행렬이 존재하지 않으므로 발생, LinAlgError -> Singular matrix