TL;DR
The outer product takes two vectors and produces a grid that holds every product of one entry from the first with one entry from the second. If the first vector has numbers and the second has , the grid is an Matrix. It is the natural way to build a matrix from two lists, and it is the basic piece from which many larger matrices are assembled.
Builds on: Vector, Matrix, Matrix Transpose · Leads to: Low-Rank Matrix, Covariance Matrix, Singular Value Decomposition (SVD)
Where it's used
Covariance matrices in statistics. When you measure several quantities for many people, say height and weight, the covariance matrix records how each pair of quantities moves together. Each person's centred measurements form a vector, and the covariance matrix is the average of that vector's outer product with itself, summed over people. Financial analysts use the same construction to study how stocks move together.
Learning in neural networks. In a dense layer that maps an input vector to an output vector, the Gradient of the loss with respect to the weight matrix is an outer product of the output error and the input. Training the weights therefore adds many outer products. Backpropagation computes these pieces efficiently.
Compressing images and data. A Singular Value Decomposition (SVD) writes a matrix as a sum of outer products, each built from a pair of singular vectors and weighted by a size. Keeping only the largest few terms gives a Low-Rank Matrix that is close to the original, which is how a picture can be stored with far fewer numbers.
How it works
Take two small vectors. Let be a column with two entries, and a row with three entries. We build a grid with two rows and three columns.
- Write as a column and as a row. has 2 entries, so it becomes a column of height 2. has 3 entries, so it becomes a row of width 3. Check: the grid will have 2 rows and 3 columns.
- Fill row 1 by multiplying the first entry of by each entry of . The first entry of is 1, so row 1 is , , . Check: row 1 is , which is just itself.
- Fill row 2 the same way with the second entry of . The second entry is 2, so row 2 is , , . Check: row 2 is , which is .
- Read off the result. The outer product is Check: it has 2 rows and 3 columns, one entry for each pair (row index of , column index of ).
- Notice the pattern. Every row is a multiple of the same row vector, . The first row is 1 times it and the second is 2 times it. Check: all rows point in one direction, so the matrix has only one independent row.
The outer product is the grid of all pairwise products. Its entry in row and column is simply the -th entry of the column times the -th entry of the row. Nothing is added up. This is what separates it from the Dot Product, which multiplies entries pairwise and then adds them into one number.
flowchart LR U["u as a column (2 entries)"] --> G[Multiply every u entry by every v entry] V["v as a row (3 entries)"] --> G G --> M["2 by 3 matrix"]
The math
For a column vector with entries and a column vector with entries, the outer product is the matrix where is the -th entry of , is the -th entry of , and denotes the entry in row and column .
Step 1 in symbols: the shapes
is an column and is a row. Multiplying an matrix by a matrix gives an matrix, because the inner dimensions, both equal to 1, cancel. In the example, and .
Step 2 and 3 in symbols: filling the grid
The formula says that row of the result is times . In the example, row 1 is times , and row 2 is times , which gives .
Step 5 in symbols: the rank-one pattern
Every row is a scalar multiple of , so the matrix has rank one. Equivalently, applying it to any vector gives The term is a dot product and therefore a single number, so the output is always a multiple of . Check with : , and the output is , which matches the first column of the matrix.
Sums of outer products
Outer products add entry by entry, so a sum of them is also a valid matrix construction. Take two data points, and . Then This is the kind of sum that gives a covariance matrix once the points are centred and averaged.
Worked examples
Let and .
- has 2 entries and has 2 entries, so the result is a matrix.
- Row 1 is times , which is .
- Row 2 is times , which is .
- The result is .
- Check: the second row is zero because , and the first row is exactly .
Let and . Here has three entries and has two.
- The result is a matrix: three rows, two columns.
- Row 1 is times , which is .
- Row 2 is times , which is .
- Row 3 is times , which is .
- The result is .
- Check: the entry in row 2, column 2 should be . It is.
A neural-network layer takes a two-number input and produces outputs. During training, the error at the outputs is , a two-number vector, one entry per output. The gradient of the loss with respect to the layer's weight matrix is the outer product .
- has 2 entries and has 2 entries, so the gradient is a matrix. Each entry is one weight's gradient.
- Row 1 is times , which is .
- Row 2 is times , which is .
- The gradient is .
- Interpretation: the weight from input 2 to output 1 has gradient , so increasing it raises the loss. The weight from input 1 to output 2 has gradient , so increasing it lowers the loss.
Try it: the output error is and the input is . Compute and say which weights have zero gradient. Answer: . The second output has zero error, so both of its weights have zero gradient.
Common mistakes and tradeoffs
It is tempting to think that the outer product of two vectors is a number, as with the Dot Product. In fact the dot product adds the pairwise products into one number, while the outer product keeps every pairwise product in its own cell. The two look alike on paper, so check the transpose: it goes on the second vector for the outer product and on the first for the dot product.
It is tempting to think that and are the same. In fact the second is the transpose of the first, so they have different shapes unless , and even then they are generally different. Order matters.
It is tempting to think that an outer product can hold a lot of information. In fact it has rank one: every row is a multiple of one row, so it captures a single pattern. Information in larger matrices comes from adding several outer products, as the low-rank and covariance examples show.
When to use it. Use the outer product when you want a matrix built from two lists, when you are summing per-example updates in learning, or when you are building a rank-one piece of a decomposition.
When not to use it. Do not use it when you only need a single number from two vectors (use the dot product), or when the two vectors are very large and you can avoid storing the full grid. The result has entries, which can be far more than the numbers that define it.
Alternatives. The Tensor Product generalises the outer product to more than two dimensions and to abstract spaces. Writing the result as a product of a column and a row, as in , is the simplest form.
History
Before the mid-1800s, matrices were mostly studied as tables of coefficients for systems of equations, and the vector and matrix notations we use today were still forming. In the late 1800s, Josiah Willard Gibbs and Oliver Heaviside developed vector analysis as a language for physics. Gibbs called products of two vectors that produce a tensor-like object dyadics, and the outer product is the matrix form of that idea.
The construction caught on in the 20th century because statistics and engineering needed matrices built from data. Covariance matrices, least squares and later neural networks all rely on sums of outer products. Today it is one of the standard operations in numerical libraries.
Recap
- A vector is a list of numbers, and a matrix is a grid of numbers. The transpose turns a column into a row.
- The outer product makes an grid whose entry in row , column is .
- Every outer product has rank one: its rows are all multiples of one row.
- Adding outer products builds larger matrices, such as covariance matrices and low-rank approximations.
- Read next: Low-Rank Matrix for matrices built from a few outer products, and Covariance Matrix for the statistics use.