Foundations · 1
Vectors & dot products
A vector is a list of numbers with a direction and a length. Everything below runs in this page — edit any block and press Run, or ⌘/Ctrl + Enter.
A vector is a 1-D tensor
One axis, a handful of numbers. Its length — the L2 norm — is the square root of the sum of squares.
Adding and scaling
Add two vectors component by component; scale one by a number. In borch.ts an operator takes a tensor, so a scalar is written Tensor.full([], k).
The dot product
a.dot(b) multiplies matching entries and sums them — one number. Geometrically it is |a||b|cos θ, so it reads the angle between two directions.
Seeing alignment: the Gram matrix
Stack a few vectors as rows and multiply by the transpose — cell (i, j) is the dot product of vector i and vector j. Brighter means more aligned; the diagonal is each vector's squared length.
Your turn: make them perpendicular
Two vectors are perpendicular exactly when their dot product is zero. Change b below so that a · b = 0 — then the page says you have it.
What to remember
- A vector is a 1-D tensor; its length is the L2
norm, the square root of the sum of squares. - The dot product
a·bsums the products of matching entries — one number measuring alignment (|a||b|cos θ). - Two vectors are perpendicular exactly when their dot product is zero.
- In borch:
a.dot(b),a.norm(); values read back withawait.