Vectors as Arrows, Points, and NumPy Arrays
Every idea later in this course, norms, dot products, matrix transformations, eigenvectors, is built on top of one small object: the vector. If you can see a vector as a geometric arrow and also type it as a NumPy array without hesitation, the rest of the course becomes drawing pictures plus careful bookkeeping. This is the first lesson, so we start from zero.
By the end of this lesson you should be able to:
- describe one vector in three equivalent ways: arrow, point, coordinate list
- read coordinates as "how far along each axis"
- build vectors with
np.arrayand inspect theirshape - add two vectors tip to tail and predict the result before running code
- scale a vector and say whether it stretches, shrinks, or flips
One Object, Three Pictures
A vector in the plane is just two numbers, for example $v = (3, 2)$. The same pair of numbers supports three readings:
- Arrow: start at the origin, walk 3 steps along the first axis and 2 along the second. What you get is an arrow with a direction and a length.
- Point: the endpoint $(3, 2)$ is a location in space.
- List:
[3, 2]is a small collection of numbers. This is the form NumPy works with.
flowchart LR
V["๐ข<br/>Vector (3, 2)"]
A["โก๏ธ<br/>Arrow: direction and length"]
P["๐<br/>Point: a location"]
L["๐งฎ<br/>List: a NumPy array"]
V --> A
V --> P
V --> L
Why keep all three? The list view is what the computer calculates with. The arrow view is what tells you whether the answer is plausible. When NumPy returns something strange, you redraw the arrows and usually spot the mistake immediately.
Reading Coordinates Off the Grid
The first number is always the horizontal axis, the second the vertical axis. A third number would add depth. Order matters: $(3, 2)$ and $(2, 3)$ are different arrows. Also, the number of entries is the dimension of the vector: two entries, two dimensions; five entries, five dimensions that we simply cannot sketch.
Note: Coordinates only make sense relative to a chosen origin and a chosen set of axes. Move the axes and the numbers change, even though the arrow in the world does not. We return to this idea in Module 2 under change of basis.
Practice 1. Sketch $(2, 3)$ and $(3, 2)$ starting from the origin. Are they the same arrow?
Click to reveal the answer
No. $(2, 3)$ goes 2 right and 3 up; $(3, 2)$ goes 3 right and 2 up. They are mirror images across the diagonal line $y = x$, pointing in different directions.
Practice 2. How many numbers does a vector in 5-dimensional space have, and what does that mean geometrically?
Click to reveal the answer
Five numbers, one per axis. We cannot draw it, but no arithmetic rule changes; the same addition and scaling code works unchanged.
Building a Vector in NumPy
import numpy as np
v = np.array([3.0, 2.0])
w = np.array([1.0, 4.0])
print(v) # [3. 2.]
print(v.shape) # (2,)
print(v.ndim) # 1
print(v[0], v[1]) # 3.0 2.0
The shape (2,) means "one dimension, two entries". Indexing starts at 0, so v[0] is the first coordinate. Writing the numbers as floats (3.0 rather than 3) is a habit worth adopting early, because later steps involve division and square roots.
One trap catches almost everyone: np.array([[3, 2]]) has shape (1, 2). That is a single row of a matrix, not a plain vector of shape (2,). The two behave differently in arithmetic.
Practice 3. Create the 3D vector $(1, 0, -2)$, print its shape, and print its last entry using negative indexing.
Click to reveal the answer
u = np.array([1.0, 0.0, -2.0])
print(u.shape) # (3,)
print(u[-1]) # -2.0
Adding Vectors Tip to Tail
Draw $v$, then place the tail of $w$ on the tip of $v$. The sum runs from the start of $v$ to the final tip. In coordinates you simply add matching entries:
$$ v + w = (3, 2) + (1, 4) = (4, 6) $$
v + w # array([4., 6.])
np.add(v, w) # same result
Addition is commutative: $v + w = w + v$, and the picture is a parallelogram either way. It also means that walking $v$ then $w$ leaves you at the same place as walking $w$ then $v$.
Practice 4. For $v = (3, 2)$, compute $v + (-v)$ by hand and describe the arrow.
Click to reveal the answer
$(0, 0)$, the zero vector. The arrow has no length and no direction; you are back at the origin.
Practice 5. Predict np.array([3.0, 2.0]) + np.array([1.0, 4.0]) before running it. Then predict what happens if you add a length-2 vector to a length-3 vector.
Click to reveal the answer
The first gives array([4., 6.]). The second raises a broadcasting error because the shapes differ; NumPy will not silently guess what you meant unless one operand has a compatible shape.
Scaling a Vector: Stretch, Shrink, Flip
Multiplying by a single number (a scalar) multiplies every entry:
2 * v # array([6., 4.])
0.5 * v # array([1.5, 1.])
-v # array([-3., -2.])
Geometrically: a positive scalar keeps the direction and changes the length; a scalar between 0 and 1 shrinks the arrow; a negative scalar flips it to point the opposite way; zero collapses it to the origin. Formally, $c,v = (c,v_1, c,v_2)$.
Measuring exactly how long the arrow is belongs to the next lesson, but you can already feel the effect: $2v$ is visibly twice as long as $v$.
Practice 6. For $v = (3, 2)$, compute $3v$ and $-1 \cdot v$, then describe each arrow relative to $v$.
Click to reveal the answer
$3v = (9, 6)$: same direction, three times as long. $-v = (-3, -2)$: identical length, opposite direction.
Practice 7. Which scalar $c$ sends any vector to the zero vector, and why does the zero vector have no direction?
Click to reveal the answer
$c = 0$. The zero vector has no length, so there is no arrow left to point anywhere.
Drawing Before Typing: Habits Worth Building
- Sketch 2D and 3D vectors on paper first. The sketch predicts the sign of every coordinate, and NumPy confirms it.
- Always check
.shapebefore adding or scaling. Most beginner bugs are shape bugs, not math bugs. - Know the difference between
(2,),(1, 2)and(2, 1). They are a vector, a row, and a column, and they behave differently. - Use
np.zeros(3),np.ones(3)andnp.arange(3)for quick test vectors instead of typing entries by hand. - Write decimals as floats. Integer arrays truncate when you divide.
Warning: Broadcasting can quietly turn a mistake into a wrong-but-running program. If a result has an unexpected shape, stop and check the inputs rather than trusting the output.
Where This Lands
You now hold the core picture: a vector is one object seen three ways, and NumPy gives you two operations, adding and scaling, that match the geometry exactly.
- A vector is an arrow, a point, and a list of coordinates at the same time.
- Coordinate order matters, and the number of entries is the dimension.
np.array([3.0, 2.0])has shape(2,);np.array([[3.0, 2.0]])does not.- Adding places arrows tip to tail and works componentwise.
- Scaling stretches, shrinks, or flips the arrow.
Fill in the blanks to check yourself:
- A plain vector in NumPy is created with _____.
- In the vector $(3, 2)$, the second number means _____.
- Adding two vectors tip to tail gives an arrow from the start of the first to _____.
- Multiplying a vector by $-1$ _____.
- The shape of
np.array([3.0, 2.0])is _____.
Next up is Norms and Distances, where we finally put a number on the length of these arrows and on the distance between two points.
Front: Name the three ways this lesson reads a vector. Back: As an arrow, as a point, and as a list of coordinates in a NumPy array.
Front: In the 2D vector (3, 2), what does each number mean? Back: 3 units along the first (horizontal) axis and 2 along the second (vertical) axis.
Front: Is (3, 2) the same vector as (2, 3)? Back: No, coordinate order matters; the two arrows point in different directions.
Front: What does the NumPy shape (2,) mean? Back: A rank-1 array with two entries, one coordinate per axis.
Front: What shape does np.array([[3.0, 2.0]]) have? Back: (1, 2), a single row rather than a plain vector of shape (2,).
Front: What is the dimension of a vector with four entries? Back: Four: one coordinate per axis.
Front: How do you add two vectors geometrically? Back: Place the tail of the second at the tip of the first; the sum runs from start to final tip.
Front: What is the tip-to-tail sum of (3, 2) and (1, 4)? Back: (4, 6), obtained by adding matching entries.
Front: Is vector addition commutative? Back: Yes: v + w = w + v.
Front: What is v + (-v)? Back: The zero vector (0, 0), which puts you back at the origin.
Front: What does multiplying a vector by a positive scalar do? Back: Stretches or shrinks it while keeping the same direction.
Front: What does multiplying a vector by a negative scalar do? Back: Flips it so it points in the opposite direction.
Front: Which scalar sends any vector to the zero vector? Back: c = 0.
Front: Which NumPy call builds the vector (1, 0, -2)? Back: np.array([1.0, 0.0, -2.0]).