Numbers & Math

Matrix Operations Cheat Sheet

Matrix arithmetic rules, transpose, inverse, determinant, and key properties.

Basic operations

Sum / differenceElement-wise; same shape required
Scalar multiplicationEach element × scalar
Matrix product A · B(m×n)·(n×p) → (m×p); inner dims must match
Transpose AᵀSwap rows and columns
Inverse A⁻¹A · A⁻¹ = I. Exists iff det(A) ≠ 0
Identity IDiagonal of 1s, elsewhere 0. I · A = A · I = A

Properties

Non-commutativeAB ≠ BA in general
Associative(AB)C = A(BC)
DistributiveA(B + C) = AB + AC
Transpose rules(A+B)ᵀ = Aᵀ + Bᵀ; (AB)ᵀ = BᵀAᵀ
Inverse rules(AB)⁻¹ = B⁻¹ A⁻¹; (Aᵀ)⁻¹ = (A⁻¹)ᵀ

Determinant

2×2det([[a,b],[c,d]]) = ad − bc
3×3Sarrus or cofactor expansion
Propertiesdet(AB) = det(A)·det(B); det(Aᵀ) = det(A); det(A⁻¹) = 1/det(A)

Special matrices

NameProperty
SymmetricA = Aᵀ
Skew-symmetricA = −Aᵀ
OrthogonalAᵀ · A = I (Aᵀ = A⁻¹)
DiagonalNon-zero only on main diagonal
Triangular (upper/lower)Zero below/above diagonal
Unitary (complex)A*·A = I
Positive definitexᵀAx > 0 for all x ≠ 0

Eigen

Eigenvalue eqA·v = λ·v
Characteristicdet(A − λI) = 0
TraceSum of diagonal = sum of eigenvalues
DetProduct of eigenvalues

Worked example: a 2×2 from start to finish

Let A = [[1, 2], [3, 4]] and B = [[0, 1], [1, 0]]. The product AB takes rows of A against columns of B: row 1 gives 1×0 + 2×1 = 2 and 1×1 + 2×0 = 1; row 2 gives 3×0 + 4×1 = 4 and 3×1 + 4×0 = 3. So AB = [[2, 1], [4, 3]]. But BA = [[3, 4], [1, 2]], which is different, showing that multiplication is not commutative (here B swaps columns when it multiplies on the right and rows on the left).

The determinant of A is 1×4 − 2×3 = −2, which is not zero, so the inverse exists: A⁻¹ = (1 / −2) × [[4, −2], [−3, 1]] = [[−2, 1], [1.5, −0.5]]. Check the first row against A: 1×(−2) + 2×1.5 = 1 and 1×1 + 2×(−0.5) = 0, and the second row similarly gives 0 and 1, so A A⁻¹ = I.

Eigenvalues come from the trace (5) and determinant (−2): λ² − 5λ − 2 = 0, so λ = (5 ± √33) / 2, about 5.372 and −0.372. They sum to 5, the trace, and multiply to −2, the determinant.

Common mistakes

  • Shape mismatch. A 3×2 matrix times a 3×2 matrix is undefined; the inner dimensions (2 and 3) must match.
  • Element-wise versus matrix product. In NumPy, * multiplies element by element and @ is the matrix product.
  • Wrong order when inverting a product. (AB)⁻¹ = B⁻¹A⁻¹, and (AB)ᵗ = BᵗAᵗ; the order reverses.
  • Inverting a singular or nearly singular matrix. If the determinant is zero there is no inverse; if it is tiny compared with the entries, results are numerically unreliable.
  • Assuming det(A + B) = det(A) + det(B). It does not; the determinant is multiplicative, not additive.
Was this article helpful?