Linear Algebra - (Dot|Scalar|Inner) Product of two vectors

Card Puncher Data Processing


A dot Product is the multiplication of two two equal-length sequences of numbers (usually coordinate vectors) that produce a scalar (single number)

Dot-product is also known as:

  • scalar product
  • or sometimes inner product in the context of Euclidean space,

The name:


For two vectors <math>u</math> and <math>v</math> , you may see the dot product of <math>u</math> and <math>v</math> represented as: <MATH>u \cdot v </MATH> or: <MATH> u^\top v </MATH>


This operation can be defined either algebraically or geometrically.


The sum of the products of the corresponding entries of the two sequences of numbers.

Dot-product of two D-vectors is sum of product of corresponding entries:

<MATH> u · v = \sum_{k \in D}{u_k.v_k} </MATH>


The product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them.

<MATH> u.v = ||u|| ||v|| \cos \theta </MATH> where:

  • cos is the cosine
  • and <math>||u||</math> and <math>||v||</math> are the norm of each vector



  • For traditional vectors u = [u1, . . . , un] and v = [v1, . . . , vn]:

<MATH> u · v = u_1.v_1 + u_2.v_2 + \dots + u_n.v_n </MATH>

  • Dot-product of [1, 1, 1, 1, 1] and [10, 20, 0, 40,-100]
   1   1    1    1       1
x 10   20   0   40    -100
= 10 + 20 + 0 + 40 + (-100) = -30

Python Code


def list_dot(u, v): return sum([a*b for (a,b) in zip(u,v)])


A quantity and price vector

quantity = {"lemon": 2, "orange" : 3}
price = {"lemon": 1.5, "orange" : 2}
quantity x price = 2x1.5 + 2x3 = 9


Similarity calculation between vectors (See also The Fast Fourier Transform).

  • When the value of the dot product is positive of maximal the two vectors tend to agree.
  • When the value of the two vectors is negative of minimal the two vectors tend to disagree.

Example: similarity in voting system: With a voting system (neutral:0, for:1, against:-1) if both values of two votes are 1, the corresponding term in the sum is 1. If both values are -1, the corresponding term in the sum is also 1. Thus a term in the sum that is 1 indicates agreement.

See also What is the Cosine Similarity or Cosine Distance? (Measure of Angle)

Documentation / Reference

Discover More
Thomas Bayes
Data Mining - (Stochastic) Gradient descent (SGD)

Gradient descent can be used to train various kinds of regression and classification models. It's an iterative process and therefore is well suited for map reduce process. The gradient descent update...
Vector Addition Arrow
Linear Algebra - Vector Vector Operations

Vector Vector Operations: (also known as addition or substraction) (Scaling) Using operator overloading, you can compute this operations with the following syntax. Operation Syntax...
Text Mining
Natural Language - Document (Cosine) Similarity

Cosine similarity applied to document similarity. Each document becomes a vector in some high dimensional space. To compare two documents we compute the cosine of the angle between their two document...
Card Puncher Data Processing
Python - NumPy

NumPy is a Python library for working with arrays. NumPy provides abstractions that make it easy to treat these underlying arrays as vectors and matrices....
Thomas Bayes
What is the Cosine Similarity or Cosine Distance? (Measure of Angle)

The cosine similarity (or cosine distance) is a distance that measures the angle between two vectors, normalized by magnitude. You just divide the dot product by the magnitude of the two vectors. ...

Share this page:
Follow us:
Task Runner