What Is a Vector?
A vector is an ordered list of numbers with a job.
The numbers are called coordinates. The job tells us what the list means. The same list can describe a point, a direction, a measurement, or a learned representation inside a model.
[2, 4]
By itself, this is only a list. In this chapter, we usually read it as two coordinates:
first coordinate = 2
second coordinate = 4
That means we can draw it from the origin to the point (2, 4).
The diagram shows two vectors. Drag an endpoint and watch the coordinates change. The useful habit is to keep the list of numbers connected to the object it represents.
Coordinates
In two dimensions, a vector has two coordinates:
The first coordinate moves along the horizontal axis. The second coordinate moves along the vertical axis.
For example:
v = [2, 4]
means:
move 2 units horizontally
move 4 units vertically
If v = [3, 5], what is the second coordinate?
Compute it first, then check your number.
HintRead from left to right
The first coordinate is 3. The second coordinate is the next number.
SolutionCoordinate order
In v = [3, 5], the coordinates are ordered. The first coordinate is 3.
The second coordinate is 5.
Order Matters
The vector:
[2, 4]
is not the same as:
[4, 2]
The same two numbers appear, but their jobs have changed. If the first
coordinate means horizontal movement, then [2, 4] moves 2 horizontally and 4
vertically. The vector [4, 2] does the opposite.
Enter 1 if [2, 4] and [4, 2] are different vectors.
Compute it first, then check your number.
HintUse Chapter 1
Vectors behave like ordered collections. Position matters.
SolutionDifferent coordinates
Enter 1. In [2, 4], the first coordinate is 2. In [4, 2], the first
coordinate is 4.
The two lists contain the same numbers, but the coordinate positions have changed. For vectors, order is part of the meaning.
Why Vectors Matter
Machine learning turns many things into vectors.
- An image patch can become a vector of pixel values.
- A token, sentence, or document can become an embedding vector.
- A model layer can produce a vector of activations.
- A user or item can be represented by a vector of learned features.
Once something is a vector, we can compute with it. We can add it, scale it, measure its length, compare it with another vector, and feed it into a model.
A vector is written as [7, 2]. Enter 1 if you still need to know what the
two coordinates mean before interpreting it in a real problem.
Compute it first, then check your number.
HintAsk what is measured
Are the coordinates pixels, rooms, activations, positions, or something else?
SolutionMeaning attached
Enter 1. The list [7, 2] gives the numbers, but the problem tells us
what those numbers mean.
Vector Versus Plain List
A vector is stored like a list, but it is not interpreted like a random list. The coordinates share one coordinate system.
For example:
[temperature, humidity]
and:
[height, weight]
may both have two numbers, but they are not the same kind of vector. Adding them would mix unrelated coordinate meanings.
Enter 1 if [20, 70] as [temperature, humidity] should not be added
directly to [20, 70] as [height, weight].
Compute it first, then check your number.
HintAsk what each position means
The first coordinate in one vector is temperature. The first coordinate in the other vector is height.
SolutionSame shape, different meaning
Enter 1. Both lists have two entries, but their coordinate systems are
different. Vector operations should combine coordinates with matching
meaning.
Code Mirror
In NumPy, a vector is usually stored as a one-dimensional array:
import numpy as np
v = np.array([2, 4])
print(v)
The output is:
[2 4]
The code is simple because the idea is simple: a vector is a structured list of numbers.
If v = np.array([2, 4]), how many coordinates does v have?
Compute it first, then check your number.
HintCount entries
The array contains 2 and 4.
SolutionTwo coordinates
The array contains two numbers:
[2, 4]
So the vector has 2 coordinates. In this lesson, those two coordinates
can be read as horizontal and vertical components.
Next, we read the same coordinates in two ways: as position and as direction.