Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter4. Vectors as Points and Directions

In this Chapter we will solve the following question:

Vectors are often introduced as lists of numbers, but this definition alone does not explain why vector are so important.

In this chpater, we break this question into smaller and slove it one by one.

Q1: Is a vector just a list of numbers?

At first glance, a vector looks like a simple list:

import numpy as np

x = np.array([1,2,3])

print(x)
[1 2 3]

This suggests that a vector is just a container of values. However, this view is incomplete.

The same list of number can represent:

So the key question is :

Q2: How can a vector represent a point?

Consider a simple vector:

x = np.array([1,2])
print(x)
[1 2]

We can interperet this as a point in 2D space:

So vector represent the point (1,2).

import matplotlib.pyplot as plt
plt.scatter(x[0], x[1])
plt.show
<function matplotlib.pyplot.show(close=None, block=None)>
<Figure size 640x480 with 1 Axes>

Hence a vector can encode location.

Q3 How can the same vector represent a direction?

Now interpret the same vector differently, instead of a point, think of it as an arrow from the origin.

(0,0) -> (1,2)
Loading...

This arrow has :

A vector can encode movement.

Q4 How do we measure vectors?

If vectors represent positions or directions, we need ways to measure them.

(1) length(magnitude)

The length of a vector tells us how far it is from the origin.

x = np.array([3,4])
np.linalg.norm(x)
np.float64(5.0)

this returns:

32+42=5\sqrt{3^2 + 4^2} = 5
Loading...

(2) Direction(unit vector)

We can separate direction from magnitude:

x = np.array([3,4])
unit = x/np.linalg.norm(x)
print(unit)
[0.6 0.8]
Loading...

Q5 How do vector interact?

Vector become powerful when we combine or compare them.

(1) Vector addition

a = np.array([1,2])
b = np.array([2,1])

Interpretation:

(2) Dot product

a = np.array([1,2])
b = np.array([2,1])

print(a @ b)
4

this computes:

1×2+2×1=41 \times 2 + 2 \times 1 = 4

But the meaning is deeper:

The dot product measures alignment.

(3) Orthogonality

if

a=[1,0]a = [1,0 ]

b=[0,1]b =[0,1]

then

a×b=0a \times b = 0
a = np.array([1,0])
b = np.array([0,1])

this means vectors are independent, they do not share directions.

Q6 Why does this matter for data science?

# feature vector (height, weight)
x = np.array([170,64])
# model weights
w = np.array([0.3,0.7])
prediction = w @ x
print(prediction)
95.8

You should imagine: