Recommended resources
The freely available resources this lesson will direct you to.
- Vectors | Chapter 1, Essence of linear algebrawww.youtube.com
- Intro to vectors & scalars | One-dimensional motion | Physics | Khan Academywww.youtube.com
- 8.4: Vectors - Mathematics LibreTextsmath.libretexts.org
- 2.2 Coordinate Systems and Components of a Vector - University Physics Volume 1 | OpenStaxopenstax.org
Welcome to the vectors module. A vector can describe a movement on a screen, a set of prices, or a collection of measurements about a piece of text. The same mathematical format works for all three, but the meaning of each number depends on the situation. Today you’ll learn to build and read vectors before doing calculations with them. Allow about 40 minutes, including the short video, reading, and a small NumPy check.
From one number to a movement
Suppose you move a pointer 4 units left and 3 units up. Saying only “it moved 5 units” would leave out where it went. To describe the movement, choose two directions: horizontal and vertical. Let positive horizontal mean right, and positive vertical mean up.
The movement is then represented by the vector
Read it in order: 4 units left, then 3 units up. The minus sign means “opposite the chosen positive direction”; it does not mean the movement is invalid. A vector’s entries are called its components.
A movement vector is often drawn as an arrow. The arrow shows direction, while its length shows how large the overall movement is. The image below shows these as two ways of describing one vector; you do not need to calculate its angle today.
Now watch how an arrow becomes an ordered list of numbers—and how an ordered list can represent something other than movement.
Vectors | Chapter 1, Essence of linear algebra
Watch “Vectors | Chapter 1, Essence of linear algebra” by 3Blue1Brown for its visual connection between arrows and data.
Start with data as vectors, where two property attributes become a two-entry vector. Then watch arrows and coordinates; focus on what the first and second numbers tell you to do on the grid. Finish with both viewpoints, which explains why moving between pictures and numbers is useful.
For now, an important distinction is that a point says where something is; a displacement vector says how its position changed. You can draw a displacement arrow starting somewhere other than the origin and still describe the same horizontal and vertical change. Drawing it from the origin simply makes its components easier to see.
Turning two positions into one vector
Imagine a pointer beginning at position and ending at , with coordinates measured rightward and upward from the bottom-left corner of a display. Its horizontal position changed from 6 to 2, so the horizontal component is . Its vertical position changed from 1 to 4, so the vertical component is .
Thus its displacement is the vector . Notice that is the ending position, not the displacement. To find a change, subtract the starting coordinate from the ending coordinate in each direction.
Read the mouse-pointer example in OpenStax’s 2.2 Coordinate Systems and Components of a Vector. It uses this same idea with measurements in centimeters.
2.2 Coordinate Systems and Components of a Vector - University Physics Volume 1 | OpenStax
Read OpenStax’s mouse-pointer example to see how two positions produce one displacement vector.
In Section 2.2, begin with the paragraph immediately before “Example 2.3: Displacement of a Mouse Pointer,” which explains subtracting beginning coordinates from ending coordinates. Read through the example, stopping at the final sentence under “Significance.” Focus on why the horizontal component is negative and the vertical component is positive.
One practical detail matters when writing software: state your coordinate convention. We chose “up is positive.” Some screen-coordinate systems instead count downward as positive, so the same physical movement would have a different vertical sign under that convention. The numbers make sense only when you know what their positions and signs mean.
Vectors that are not movements
An ordered list can also keep several related quantities together. Suppose three products have prices of 4, 12, and 3 currency units. If you fix the order as notebook, headphones, pencil, their price vector is
The first entry means “notebook price,” the second “headphones price,” and the third “pencil price.” Switching the first two entries would describe different prices for those products. This is a three-dimensional vector because it has three components—not because you must imagine three physical directions in a shop.
The same approach represents features: numbers chosen to describe an item. For a piece of text, we might define the features, in order, as:
- number of words;
- number of question marks;
- whether it contains code, using 1 for yes and 0 for no.
Text with 18 words, one question mark, and no code would have the feature vector
This vector is a compact description, not a movement. Its entries even have different meanings, so interpreting it as a literal physical arrow would not help much. In machine learning, specifying what each entry represents is as important as writing down the entries themselves.
Language models also work with numerical vectors representing text. Their internal features are generally learned rather than simple hand-chosen counts like the three above. For now, the useful foundation is more modest: a vector holds numbers in a fixed order, and that order lets a model treat each position consistently.
A small NumPy check
First identify the components and their meanings by hand. Then you can store them in NumPy arrays:
import numpy as np
displacement = np.array([-4, 3])
prices = np.array([4, 12, 3])
text_features = np.array([18, 1, 0])
print(displacement.shape) # (2,)
print(prices.shape) # (3,)
print(prices[1]) # 12
A shape of (3,) tells you there are three entries in a one-dimensional array. It does not tell you whether those entries are prices, text features, or coordinates. Likewise, prices[1] returns 12 because Python indexing starts at zero; your stated product order tells you that 12 is the headphones price.
NumPy stores the numbers. You supply their meaning.
Where this leaves us
You can now represent a two-direction movement with signed components, find displacement from starting and ending positions, and build ordered vectors for prices or features. The central habit is to define the meaning and order of entries before calculating anything.
Next, you’ll use NumPy to add vectors and multiply them by a number. Those operations will be much easier to interpret now that each component has a clear role.