Vectors, explained with pictures
A vector is an arrow. Grab the tip of an arrow and drag it. You will see what adding, scaling and the dot product look like.
Short answer. A vector is an arrow with a direction and a length. In numbers, you write it like (3, 1). That means "3 to the right, 1 up." Something with just one number (a temperature, a weight) is called a scalar.
a = ( , )
b = ( , )
Drag the circles at the arrow tips, or change the numbers.
Definitions
The text below explains things with arrows on a plane, which have two numbers, but the definitions are the same with n numbers. u and v are vectors in ℝⁿ, and c is a real number.
- vector
- An ordered list of n real numbers, v = (v₁, v₂, …, vₙ), is a vector in ℝⁿ. ℝⁿ is the set of all such vectors.
- component
- vᵢ is the i-th component of v. Two vectors are equal when all their components are equal.
- zero vector
- The vector whose components are all 0. Adding it to any vector leaves that vector unchanged.
- addition
- Add the components in the same position.
- scalar multiplication
- Multiply every component by the same real number c.
- norm (length)
- The positive square root of the sum of the squares of the components. It is the length of the arrow.
- unit vector
- A vector with norm 1. If v ≠ 0, dividing v by its own norm gives the unit vector in the same direction as v.
1. Adding: one walk after another
To add two vectors, add across to across, and up to up. (3, 1) + (1, 2.5) = (4, 3.5). In the picture, you walk along a, then from there you walk along b. The dashed line is that path. The black arrow shows where you end up. Why across to across and up to up? Section 2 builds it one step at a time.
Try this. ① Walk b first and then a. You end up at the same place (the dashed lines form a parallelogram). ② Point b exactly opposite to a. The sum becomes (0, 0). You are back where you started.
2. How the formula is built: why add across to across, and up to up
The meaning of adding is in the picture: walk along a, then walk along b from there. That one picture gives you a + b = (a₁ + b₁, a₂ + b₂). Here a₁ and a₂ are the across and up numbers of a, and b₁ and b₂ are the same for b. The numbers are the starting values of the lab above: a = (3, 1) and b = (1, 2.5).
Press "Next" to go one step at a time. The formula above gets a new piece (the orange background marks it), the picture changes by that much, and the reason appears beside it. The dashed arrows are steps (green for the steps of a, blue for the steps of b).
Written only as equations, the steps above look like this. A step across is a vector whose second component is 0, and a step up is one whose first component is 0.
In equations, (3, 1) is written standing up, as a column. It is the same arrow.
- Split a:
a = (a₁, a₂). a = (3, 1) is two steps: 3 to the right and 1 up. - Split b:
b = (b₁, b₂). b = (1, 2.5) is two steps: 1 to the right and 2.5 up. - Tip to tail:
a + b = (a₁, a₂) + (b₁, b₂). An arrow is only a direction and a length, so moving it does not change it. Put the tail of b on the tip of a and you get the path "walk a, then walk b". Where it ends, (4, 3.5), is a + b. - Gather across and up:
a + b = (a₁ + b₁, a₂ + b₂). A step across never changes your height, and a step up never changes how far across you are. So the order of the steps does not change where you end. The end is the sum of the across steps, 3 + 1 = 4, and the sum of the up steps, 1 + 2.5 = 3.5. - Done. The straight arrow from the start to the end is a + b = (4, 3.5). Vectors with 3 or more numbers add the same way, one slot at a time (vectors in n dimensions).
3. Scaling: multiplying by one number
Multiply a vector by one number, and the direction stays the same, only the length changes. Multiply across and up by the same number. 1.5 × (3, 1) = (4.5, 1.5). Press "Scaling" above and move the slider.
Try this. ① Multiply by a number smaller than 1 and the arrow shrinks. ② Multiply by a negative number and it points the other way. ③ Multiply by 0 and it becomes a point.
4. Dot product: how much do they point the same way?
The dot product turns two vectors into one number. Multiply across by across, multiply up by up, then add. (3, 1) · (1, 2.5) = 3×1 + 1×2.5 = 5.5.
This number tells you how much the two arrows point the same way. Press "Dot product" above, and the shadow of b falls on a in orange. The dot product is the length of that shadow × the length of a.
| Dot product | Meaning | Angle between |
|---|---|---|
| Positive | They point roughly the same way | Less than 90° |
| 0 | They are at a right angle. They are unrelated | 90° |
| Negative | They point roughly opposite ways | More than 90° |
Try this. ① Turn b to a right angle with a. The shadow disappears and the dot product becomes 0. ② Point b the same way as a. The dot product is at its largest (the two lengths multiplied).
Where is it used?
- AI search. Words, sentences and images are turned into vectors of hundreds to thousands of numbers (embeddings). Things with similar meanings get vectors that point in similar directions. So the dot product or cosine similarity (the dot product with length taken out) is used to find similar things.
- Games and graphics. Position, speed and force are all vectors. How directly light hits a surface is also worked out with the dot product.
- Gradient descent. When there are many directions, the slope (the gradient) is a vector. On the gradient descent page, it is the direction the ball moves.
Common questions
What is a vector?
An arrow with a direction and a length. In numbers, you write it as a group of numbers, like (how far across, how far up).
What is the difference between a vector and a scalar?
A scalar is a single number (a temperature of 20 degrees, a weight of 3 kg). A vector is a group of numbers and has a direction (3 to the east, 1 to the north).
What does the dot product tell you?
It tells you, with one number, how much two vectors point the same way. The same way gives a positive number. A right angle gives 0. Opposite ways give a negative number.
Where are vectors used in AI?
Words, sentences and images are turned into vectors of hundreds to thousands of numbers (embeddings). Things with similar meanings get vectors that point in similar directions. So the dot product or cosine similarity is used to find similar things.
Words
| Word used here | Word used in textbooks |
|---|---|
| arrow | vector |
| one number | scalar |
| across, up | components |
| putting b on the tip of a | triangle law of vector addition, tip-to-tail method |
| length | magnitude, norm. Written ‖a‖ |
| scaling | scalar multiplication |
| dot product | inner product, scalar product. Written a · b |
| shadow | projection |