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

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:

## 3 - Representation

For two vectors $u$ and $v$, you may see the dot product of $u$ and $v$ represented as: $$u \cdot v$$ or: $$u^\top v$$

## 4 - Definition

This operation can be defined either algebraically or geometrically.

### 4.1 - Algebraic

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:

$$u · v = \sum_{k \in D}{u_k.v_k}$$

### 4.2 - Geometric

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

$$u.v = ||u|| ||v|| \cos \theta$$ where:

• cos is the cosine
• and $||u||$ and $||v||$ are the norm of each vector

## 5 - Example

### 5.1 - Algebraic

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

$$u · v = u_1.v_1 + u_2.v_2 + \dots + u_n.v_n$$

• 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

## 6 - Python Code

### 6.1 - Algebraic

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

## 7 - Application

### 7.1 - A quantity and price vector

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