Home / Maths for AI / Symbols / Vectors and matrices

Matrix inverse

Say it: "A inverse"

What it means

The matrix that undoes AA: A−1A=IA^{-1}A = I (the identity). Only square matrices with a non-zero determinant have one.

Example

(2004)−1=(0.5000.25)\begin{pmatrix} 2 & 0 \\ 0 & 4 \end{pmatrix}^{-1} = \begin{pmatrix} 0.5 & 0 \\ 0 & 0.25 \end{pmatrix}

Undoing a stretch is shrinking back.

In code

import numpy as np
A = np.array([[2.0, 0], [0, 4.0]])
print(np.linalg.inv(A))
print(np.linalg.inv(A) @ A)

Output

[[0.5  0.  ]
 [0.   0.25]]
[[1. 0.]
 [0. 1.]]

Where it appears in machine learning

The formula for linear regression, (X⊤X)−1X⊤y(X^\top X)^{-1} X^\top y. In code, solve systems with np.linalg.solve rather than inverting.

Related symbols

Learn it properly in the free lesson Matrices, with practice questions that check your answers.