VOOZH about

URL: https://www.geeksforgeeks.org/python/outer-product-on-vector/

⇱ Outer Product on Vector - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Outer Product on Vector

Last Updated : 8 May, 2025

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.

👁 Outer-Product
Geometrical Interpretation of Outer Product

Mathematical Definition of the Outer Product

Given two vectors:

their outer product is given by:

where:

Thus, the outer product results in an m×n matrix.

Numerical example

Let’s consider the vectors:

The outer product is:

Python Implementation

Using NumPy’s outer() Function

Output:

👁 outer-product-2
Outer Product

NumPy's np.outer() function efficiently computes the outer product of two vectors.

Using Matrix Multiplication

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 𝑢𝑖𝑣𝑗.

Output:

👁 outer-product-2
Outer Product

Numerical Example in Python

Let’s compute the covariance matrix using the outer product.

Output:

👁 outer-product-2
Covariance Matrix

This method is equivalent to np.cov(X.T, bias=False).

Difference Between Inner and Outer Products

  • The inner product (dot product) is:

It produces a scalar.

  • The outer product is:

It produces a matrix.

Example:

while

Applications of the Outer Product

Tensor Algebra and Physics

  • Used in quantum mechanics to represent density matrices.
  • Helps in constructing higher-order tensors.

Machine Learning and Neural Networks

  • Used in Hebbian learning for weight updates.
  • Plays a role in covariance matrix computations.

Image Processing and Computer Vision

  • Used in low-rank approximations.
  • Helps in feature engineering.

Statistical Analysis

  • The covariance matrix of a dataset is derived using the outer product.
Comment