Text & documents
Numbers & maths
Data & formats
Security
Development & DevOps
Artificial Intelligence
Finance
Health & Wellness
Productivity
Games & Entertainment
Multimedia & design
Business
How to use
Vectors: similarity and distance

Drag the tips of a and b. The dot product a·b adds up the products of their coordinates; divided by their lengths it gives the cosine, which only looks at where they point (1 = same direction, 0 = perpendicular, −1 = opposite). The Euclidean distance measures how far apart the tips are. This is how embeddings are compared: two similar texts are vectors with a high cosine.

A matrix transforms the plane

The columns of the matrix say where the basis vectors î (red) and ĵ (blue) go; the rest of the grid follows them, because the transformation is linear: straight lines stay straight and the origin does not move. The determinant is how much the area of the unit square changes (negative: it flips it over; zero: it flattens it into a line). The eigenvectors are the directions that do not turn, they are only stretched by their eigenvalue. A layer of a neural network is this, plus a shift and a non-linear function.

Composing: one transformation after another

Tick “Then apply another one” and the grid shows both in a row: first M and then N, which is the matrix N·M. Order matters: rotating then stretching is not the same as stretching then rotating.

Linear algebraVectors and matrices: dot product, distances and how a matrix transforms the plane
Linear algebraVectors and matrices: dot product, distances and how a matrix transforms the plane
a (4, 1)b (2, 3)

Drag the tips of a and b (or focus them and use the arrow keys).

Dot product a·b
4·2 + 1·3 = 11
Lengths ‖a‖ and ‖b‖
4.123 · 3.606
Cosine similarity
0.74(angle 42.3°)
Euclidean distance
2.828(Manhattan 4)
Projection of a onto b
(1.69, 2.54)

The cosine does not change if you lengthen an arrow without turning it; the distance does. Try it.