Matrix Operations
- Compute the transpose of a matrix and apply the property (AB)^T = B^T A^T
- Execute matrix addition, scalar multiplication, and matrix multiplication, checking conformability before each product
- Calculate an inner product as a dot product and interpret the result geometrically as a similarity score
- Explain why matrix multiplication is not commutative and give a concrete counterexample
- Interpret a matrix-vector product as a linear combination of the matrix columns, and connect this view to how a neural network layer transforms its input
Equality
Two matrices and are equal if and only if they have the same dimensions and every corresponding element is equal:
Dimension mismatch means not-equal regardless of element values. This seems obvious but matters when checking whether a transformation preserves matrix structure.
Transposition
The transpose of , written or , is formed by swapping rows and columns — the -th row of becomes the -th column of :
If is , then is .
Properties of the Transpose
- — transposing twice recovers the original
- — transpose distributes over addition
- — transpose reverses the order of multiplication
- — reversal extends to any product length
- is symmetric
The reversal rule catches many beginners off guard. It arises from the way inner products work: transposing a product swaps which matrix is pre- and post-multiplied.
Matrix Addition and Subtraction
Addition and subtraction are element-wise operations:
Matrices must have identical dimensions to be added — they are then said to be conformable for addition.
Properties
- Commutative:
- Associative:
- Additive identity:
Scalar Multiplication
Multiplying a matrix by a scalar scales every element:
Scalar multiplication commutes: . It distributes over addition: .
Vector Inner Product
The inner product (dot product) of two column vectors and of the same length is a scalar:
Note the form: is a row vector times a column vector, yielding a scalar. Since each term , the inner product is symmetric:
Geometrically, where is the angle between the vectors. The inner product is zero when vectors are orthogonal — a fundamental concept in least squares and PCA.
Matrix Multiplication
For an matrix and a matrix , the product is , where element is the inner product of row of with column of :
Conformability
The matrices must be conformable for multiplication: the number of columns in must equal the number of rows in . A useful check: write the dimensions in sequence — — the inner dimensions must match, and the outer dimensions give the result.
Non-Commutativity
Matrix multiplication is generally not commutative:
In fact, may not even be defined (if dimensions don't conform), or it may have different dimensions than , or it may be defined with the same dimensions but unequal to . This is why we distinguish pre-multiplication ( is premultiplied by ) from post-multiplication.
Properties
- Associative:
- Distributive:
- Identity:
- Zero matrix:
- Transpose of product:
Column Interpretation
Each column of is a linear combination of the columns of , with coefficients drawn from the corresponding column of :
This column interpretation is one of the most useful ways to think about what a matrix multiplication does: it expresses the columns of the result as combinations of the columns of the left factor.
Sums via Vectors
A column of ones (length ) provides compact notation for sums:
The arithmetic mean follows immediately:
The sum of squares and cross-products of a data matrix () take the matrix form , where element is the inner product of columns and of . This matrix is the workhorse of ordinary least squares.