Identity and Inverse
Undoing a matrix.
The number one does nothing when you multiply by it. Matrices have their own version, called the identity. And just as multiplying by a half undoes multiplying by two, many matrices have an inverse that undoes them.

- Multiplying by 1 does nothing
- The identity matrix
- The inverse undoes
np.eye and np.linalg.inv
NP dot eye makes the identity, with ones on the diagonal, and zeros everywhere else. Multiplying by it changes nothing. Lin alg dot inv finds the inverse. A times its inverse gives the identity. Run it.
import numpy as np
I = np.eye(2)
A = np.array([[2.0, 1.0], [1.0, 3.0]])
print(I)
print("A @ I equals A:", np.allclose(A @ I, A))
A_inv = np.linalg.inv(A)
print((A @ A_inv).round(10) + 0)[[1. 0.] [0. 1.]] A @ I equals A: True [[1. 0.] [0. 1.]]
Not every matrix has one
A matrix that squashes space flat, like squashing a square into a line, can't be undone, because information was lost. Those matrices are called singular, and they have no inverse. In data, this happens when one feature is an exact copy, or combination, of others. Like having price in dollars and price in cents.
| key | value |
|---|---|
| Identity | ones on the diagonal |
| A @ A⁻¹ | = I |
| Singular | squashes space, no inverse |
| In data | duplicate features |
Summary
The identity changes nothing, and the inverse undoes a matrix. Singular matrices have no inverse. Next, solving systems of equations.
Key takeaways- np.eye(n)
- np.linalg.inv(A)
- Singular: no inverse