Skip to content
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 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.

An inverse means that a transformation preserved enough information to be undone. In numerical code, solve the system rather than constructing the inverse first.

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를 먼저 떠올리면 됩니다.