Lesson

Vectors: Lists of Numbers You Can Picture

You'll read a vector as a list and an arrow, and add, scale, subtract, and multiply them (element-wise and with the dot product) β€” the exact moves a transformer runs on token embeddings.

A vector is a list of numbers

Start with the whole idea in one line: a vector is an ordered list of numbers. That’s it. Here’s one:

a=[3, 1, 4]\mathbf{a} = [3,\, 1,\, 4]

We write a vector with a bold letter and stack its numbers in square brackets. Each number is a component. We name them by position: a1=3a_1 = 3 is the first component, a2=1a_2 = 1 the second, a3=4a_3 = 4 the third β€” in general aia_i (β€œa-sub-ii”) is the number in slot ii. The count of numbers is the vector’s dimension, written nn. Our a\mathbf{a} has n=3n = 3.

You already use vectors without the name. A color on a screen is three numbers β€” how much red, green, and blue β€” so a color is a 3-dimensional vector [R, G, B][R,\, G,\, B]. Drag the sliders and watch the list and the color move together:

this colour = [80, 160, 240]

The same list is also an arrow

When a vector has 2 or 3 components, you can draw it. Read [3, 1][3,\, 1] as directions: start at the origin, go 3 right and 1 up, and draw an arrow to where you land. Same numbers, now you can see them.

So every vector has two faces: a list (good for computing) and an arrow (good for seeing). We’ll switch between them freely.

Two quick but important details:

Adding vectors

To add two vectors of the same length, add them slot by slot:

a+b=[a1+b1,Β a2+b2, …,Β an+bn]\mathbf{a} + \mathbf{b} = [a_1 + b_1,\ a_2 + b_2,\ \dots,\ a_n + b_n]

Worked example. With a=[2, 1]\mathbf{a} = [2,\, 1] and b=[3,β€‰βˆ’2]\mathbf{b} = [3,\, -2]:

a+b=[2+3,Β 1+(βˆ’2)]=[5,β€‰βˆ’1]\mathbf{a} + \mathbf{b} = [2+3,\ 1+(-2)] = [5,\, -1]

Geometrically, addition is tip-to-tail: walk along a\mathbf{a}, then from where you stop, walk along b\mathbf{b}. Where you end up is a+b\mathbf{a} + \mathbf{b}. Drag the blue and green arrows and watch the orange sum update:

a = (2, 1) Β· b = (-1, 2) Β· a+b = (1, 3) Β· cΒ·a = (3, 1.5)

element-wise aβŠ™b = (-2, 2) Β· dot aΒ·b = 0 (one number β€” multiply slot by slot, then add)

Optional depth: why add component-wise and not some other way

Each component tracks an independent quantity β€” in a color, red has nothing to do with blue. Combining two vectors should combine each quantity on its own terms: red with red, blue with blue. Mixing slots would let β€œred” leak into β€œblue,” which is meaningless. So β€œkeep every axis separate” is the definition.

Scaling vectors

To scale a vector by a single number cc (called a scalar), multiply every component by cc:

c a=[c a1,Β c a2, …,Β c an]c\,\mathbf{a} = [c\,a_1,\ c\,a_2,\ \dots,\ c\,a_n]

Worked example. With a=[3,β€‰βˆ’1]\mathbf{a} = [3,\, -1]:

The slider in the playground above scales the blue arrow β€” drag it past zero to watch it flip.

Subtracting vectors

Subtraction is just adding a flipped vector: aβˆ’b=a+(βˆ’1)b\mathbf{a} - \mathbf{b} = \mathbf{a} + (-1)\mathbf{b}, which works out component-wise to

aβˆ’b=[a1βˆ’b1,Β a2βˆ’b2, …,Β anβˆ’bn]\mathbf{a} - \mathbf{b} = [a_1 - b_1,\ a_2 - b_2,\ \dots,\ a_n - b_n]

Worked example. With a=[5, 2]\mathbf{a} = [5,\, 2] and b=[1, 3]\mathbf{b} = [1,\, 3]:

aβˆ’b=[5βˆ’1,Β 2βˆ’3]=[4,β€‰βˆ’1]\mathbf{a} - \mathbf{b} = [5-1,\ 2-3] = [4,\, -1]

There’s a clean picture: aβˆ’b\mathbf{a} - \mathbf{b} is the arrow from b\mathbf{b}β€˜s tip to a\mathbf{a}β€˜s tip β€” β€œwhat you’d add to b\mathbf{b} to reach a\mathbf{a}.” Drag the two arrows and watch the difference:

a = (3, 2) Β· b = (-1, 1) Β· a βˆ’ b = (4, 1) β€” the arrow from b's tip to a's tip.

Same size or it doesn’t work

Addition, subtraction, and the element-wise product (next) all pair up matching slots β€” so both vectors must have the same dimension. You cannot add [1, 2][1,\, 2] and [1, 2, 3][1,\, 2,\, 3]: the first vector has no third slot to pair with the 33, so the operation is undefined.

[1, 2]+[1, 2, 3]⟹undefinedΒ (differentΒ sizes)[1,\, 2] + [1,\, 2,\, 3] \quad\Longrightarrow\quad \text{undefined (different sizes)}

Scaling is the one exception β€” it’s a single number times the vector, so it works on a vector of any size.

Two ways to multiply vectors

There’s no single β€œvector times vector.” The two products that matter for AI are:

1. Element-wise (the Hadamard product, written βŠ™\odot). Multiply matching slots; the result is a vector of the same size.

aβŠ™b=[a1b1,Β a2b2, …,Β anbn]\mathbf{a} \odot \mathbf{b} = [a_1 b_1,\ a_2 b_2,\ \dots,\ a_n b_n]

Worked example. [2, 3]βŠ™[4,β€‰βˆ’1]=[2β‹…4,Β 3β‹…(βˆ’1)]=[8,β€‰βˆ’3][2,\, 3] \odot [4,\, -1] = [2\cdot4,\ 3\cdot(-1)] = [8,\, -3]. Models use this to gate β€” turning some features of a vector up and others down.

2. The dot product (written β‹…\cdot). Multiply matching slots, then add them all into one single number.

aβ‹…b=a1b1+a2b2+β‹―+anbn\mathbf{a} \cdot \mathbf{b} = a_1 b_1 + a_2 b_2 + \dots + a_n b_n

Worked example. [2, 3]β‹…[1, 4]=2β‹…1+3β‹…4=2+12=14[2,\, 3] \cdot [1,\, 4] = 2\cdot1 + 3\cdot4 = 2 + 12 = 14.

That one number measures how much two vectors point the same way β€” it’s the engine behind attention and similarity search, so it gets its own lesson soon (Lesson 3). For now, just be able to compute it. The playground above shows both aβŠ™b\mathbf{a}\odot\mathbf{b} and aβ‹…b\mathbf{a}\cdot\mathbf{b} live as you drag.

Why this matters

Transformers don’t read words β€” the first thing a model does is turn each token into a vector of learned numbers called an embedding, exactly like a color is a list of numbers. From there, the machinery is the moves you just learned: attention adds vectors together (weighted by how relevant they are), scales them, and uses the dot product to decide how much each token should attend to another; the residual stream is one long running sum. Get these operations, and the rest of the course has solid ground to stand on.

When you’re ready, the assessment mixes all of this β€” including a few that make you combine several moves in one go.

Key takeaways

Ready? Take the assessment to lock in what you learned and unlock the next lesson.

Go deeper β€” Ask an AI

Opens an external AI chat in a new tab, pre-filled with context from this lesson. This is the only feature that uses the internet.