Rectangular Arrays of Numbers
A matrix is a rectangular array of numbers arranged in rows and columns; an matrix has rows and columns. Matrices compactly represent linear systems, transformations, graphs (adjacency matrices), and data tables — they are one of computing's workhorse structures.
The operations:
- Addition — add two matrices of the same shape entry by entry.
- Scalar multiplication — multiply every entry by a number.
- Matrix multiplication — the important, non-obvious one. The product is defined only when the number of columns of equals the number of rows of . Entry of is the dot product of row of with column of . An times an matrix gives an result.
Matrix multiplication has a crucial quirk: it is not commutative — in general , and often only one order is even defined. (It is associative, .) The identity matrix (ones on the diagonal, zeros elsewhere) acts like the number 1: . A square matrix may have an inverse with , which "undoes" it — but not all matrices are invertible.
Why does this odd multiplication rule matter? Because a matrix represents a linear transformation, and multiplying matrices composes the transformations. Applying two transformations in sequence corresponds to one matrix product — which is why the "row-times-column" rule is exactly the right definition, and why order matters (doing A then B differs from B then A).
Common pitfall: assuming matrix multiplication is commutative, or multiplying entry-by-entry like addition. In general (order matters, and often only one order is defined). And the product is not formed by multiplying corresponding entries — each result entry is a dot product of a row and a column, so shapes must match ('s columns 's rows).