Vectors and the dot product
Not met yet
A vector is a list of numbers treated as one thing: an arrow, like the wind as (east, north), or one night's readings in a fixed order. In NumPy it is a one-dimensional array, so a + b puts one arrow after the other, and 2 * a doubles its length without turning it. Its length is the square root of the sum of its squares, Pythagoras in any number of dimensions: np.linalg.norm(a). The dot product, np.dot(a, b), multiplies in pairs and adds, giving one number: positive when the arrows point roughly the same way, 0 at right angles, negative when they point apart. A weighted sum, like a neuron's, is the dot product of the weights with the readings.
Try it
main.pyOutput
Press Run and what your program prints shows up here.
Easy to get wrong
- Thinks the dot product of two vectors is a vector of the pairs multiplied, rather than one number, their sum.
- Thinks a vector's length is the sum of its entries, rather than the square root of the sum of their squares.
- Thinks adding two vectors gives one whose length is the two lengths added, which is only true when they point the same way.
- Thinks a dot product of 0 means one of the vectors is all zeros, rather than that the two are at right angles.