Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

11.1: Dot Product Review

( \newcommand{\kernel}{\mathrm{null}\,}\)

We covered inner products a while ago. This assignment will extend the idea of inner products to matrix multiplication. As a reminder, Sections 1.4 of the Stephen Boyd and Lieven Vandenberghe Applied Linear algebra book covers the dot product. Here is a quick review:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

from IPython.display import YouTubeVideo
YouTubeVideo("ZZjWqxKqJwQ",width=640,height=360, cc_load_policy=True)
from IPython.display import YouTubeVideo
YouTubeVideo("ZZjWqxKqJwQ",width=640,height=360, cc_load_policy=True)

Given two vectors u and v in Rn (i.e. they have the same length), the “dot” product operation multiplies all of the corresponding elements and then adds them together. Ex:

u=[u1,u2,,un]

v=[v1,v2,,vn]

uv=u1v1+u2v2++unvn

or:

uv=ni=1uivi

This can easily be written as python code as follows:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

u = [1,2,3]
v = [3,2,1]
solution = 0
for i in range(len(u)):
    solution += u[i]*v[i]
    
solution
u = [1,2,3]
v = [3,2,1]
solution = 0
for i in range(len(u)):
    solution += u[i]*v[i]
    
solution
10

In numpy the dot product between two vectors can be calculated using the following built in function:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

import numpy as np
np.dot([1,2,3], [3,2,1])
import numpy as np
np.dot([1,2,3], [3,2,1])
10
Question

What is the dot product of any vector and the zero vector?

Question

What happens to the numpy.dot function if the two input vectors are not the same size?


This page titled 11.1: Dot Product Review is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?