![]() |
VOOZH | about |
The outer product is a fundamental operation in linear algebra that constructs a matrix from two vectors. Unlike the inner (dot) product, which results in a scalar, the outer product produces a matrix, capturing pairwise multiplicative interactions between elements of the two vectors. This operation plays a crucial role in tensor algebra, physics, and is especially prevalent in fields like machine learning and deep learning.
Given two vectors:
their outer product is given by:
where:
Thus, the outer product results in an m×n matrix.
Let’s consider the vectors:
The outer product is:
Output:
NumPy's np.outer() function efficiently computes the outer product of two vectors.
The outer product can also be computed by treating the vectors as matrices—specifically, by reshaping one vector as a column vector and the other as a row vector. The outer product is then given by:
Here, 𝑢 is a column vector and 𝑣⊤ is the transpose of a row vector, resulting in a matrix 𝐴 whose entries are all pairwise products 𝑢𝑖𝑣𝑗.
Let’s compute the covariance matrix using the outer product.
Output:
This method is equivalent to np.cov(X.T, bias=False).
It produces a scalar.
It produces a matrix.
Example:
while