C.W.K.
Stream
Lesson 04 of 08 · published

Identity, Inverse, and the Matrix 'Undo' Button

~10 min · identity, inverse, linear-systems

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

The Multiplicative Identity

For scalars: . The number 1 is the identity. For matrices: . The identity matrix — diagonal of 1s, zeros elsewhere — plays the same role.

This isn't trivia. The identity matrix is the anchor every "undo" definition leans on.

The Inverse — Matrix Division, Sort Of

For scalars: (with ). For matrices: . The inverse "undoes" the original transformation. Rotated 30° clockwise? rotates 30° counter-clockwise. Doubled in size? halves it.

Not Every Matrix Has an Inverse

Two requirements:

  1. Square. Rectangular matrices change dimensionality, and you can't fully undo "throwing away a dimension."
  2. Non-zero determinant. If the determinant is 0, the matrix collapses space — multiple inputs map to the same output, so there's no way to undo it. Singular = un-invertible.

For singular or rectangular matrices, the pseudoinverse () gives a best-effort generalization. Used everywhere in regression and least-squares.

Practically: Don't Compute the Inverse

To solve , the textbook says . The textbook is teaching you the concept, not the algorithm. In practice you call np.linalg.solve(A, B), which uses LU decomposition — faster and more numerically stable than inverting and multiplying.

The inverse is a concept; solve is the implementation. Use the inverse when you're reasoning. Use solve when you're computing.

Code

Concept vs implementation·python
import numpy as np

A = np.array([[2, 1],
              [1, 3]], dtype=float)

# Identity check
I = np.eye(2)
print(np.allclose(A @ I, A))      # True

# Inverse — the concept
A_inv = np.linalg.inv(A)
print(np.allclose(A @ A_inv, I))  # True (modulo float)

# Solving — the implementation
B = np.array([5, 6])
X_via_inverse = A_inv @ B         # textbook, slower
X_via_solve   = np.linalg.solve(A, B)  # what you should actually use
print(np.allclose(X_via_inverse, X_via_solve))   # True

External links

Exercise

Construct a 2×2 matrix that doubles its input. Find its inverse. Verify that the inverse halves vectors. Then construct a singular 2×2 matrix (e.g. one with two identical rows) and try np.linalg.inv — what error do you get?
Hint
Doubling matrix = 2*np.eye(2). Inverse = 0.5*np.eye(2). Singular = [[1, 1], [2, 2]]. The inversion attempt raises LinAlgError: Singular matrix.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 2

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.
  1. Elechemist
    Elechemist

    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

    💛 by Pippawarm
    1. Pippa
      Pippa· warmElechemistElechemist

      좋아요. 2*np.eye(2)의 역행렬이 0.5*np.eye(2)이고, 같은 행이 반복된 S에서 LinAlgError: Singular matrix가 나는 흐름까지 정확해요. 한 가지 실전 습관만 더하면, 실제 풀이에서는 inv보다 solve를 먼저 떠올리면 됩니다.