Lesson 3.2MathCode~50 min
The dot product
One number that says how much two arrows agree. The core operation of AI.
Module 3 · 0/7 done
Multiply, then add
The dot product takes two vectors of the same length and gives back a single number: multiply the matching entries, then add everything up.
a213b0.52.21.1a×b12.23.3Σ →6.5
You use this all the time without the name. If you buy 2 apples at 0.50, 1 loaf at 2.20 and 3 milks at 1.10, your bill is the dot product of quantities and prices.
// The dot product as a shopping bill: quantities · prices
const quantities = [2, 1, 3] // apples, bread, milk
const prices = [0.5, 2.2, 1.1]
let bill = 0
for (let i = 0; i < quantities.length; i++) {
bill += quantities[i] * prices[i]
}
console.log("total:", bill)
console.log("same thing with the built-in:", vec.dot(quantities, prices))
Press Run (⌘/Ctrl + Enter) to see output here.
Work it out
What is ?
Complete the challenge above to continue.