Zalgorithm

What are vectors?

This is not a math tutorial. See Why am I writing about math?

“Most generally, a vector is a list of things. In mutivariable calculus, ’thing’ typically ends up meaning ’number’, but not always.”1

Operations that can be performed on vectors

Between vectors of equal length:

Vectors can also be scaled with scalar multiplication.

Vectors versus points

When a vector is a list of numbers, it can be visualized as an arrow in space with its tail at the origin. For example (3, 4):

Vector (3, 4)
Vector (3, 4)

Python code for generating the image.

The same vector (3, 4) can be drawn with its tail at some point other than the origin (0, 0). In the image below, both arrows correspond to the same vector (3, 4), even though they have different origins. The vector (3, 4) represents the same displacement regardless of where it’s drawn from (regardless of what it’s point of origin is considered to be).

Same vector (3,4) from two different origins
Same vector (3,4) from two different origins

Python code for generating the image

Magnitude and direction

A vector has a magnitude and a direction.

The magnitude, or length, of a vector is the square root of the sum of its squares.

V=x2+y2=32+42=25=5 |\mathbb{V}| = \sqrt{x^2 + y^2} = \sqrt{3^2 + 4^2} = \sqrt{25} = 5

For 2D vectors, the magnitude is the hypotenuse, because a 2D vector can be thought of as the hypotenuse of a triangle.

Considering a single 2D vector, the direction can be expressed as the angle from the positive x-axis. For example, given the vector (3, 4), and remembering SOHCAHTOA (cosine = adjacent / hypotenuse):

The hypotenuse is also the magnitude that was calculated above:

a2=b2+c2 a^2 = b^2 + c^2 a=b2+c2=32+42=5 a = \sqrt{b^2 + c^2} = \sqrt{3^2 + 4^2} = 5 θ=3/5 \theta = 3/5

The direction of the vector (3, 4) is the angle of the cosine of the point (3, 4):

theta = 3/5
angle = np.degrees(np.arccos(theta))
angle = 53.13010235415598

Cosine similarity

Consider the vectors (3, 4) and (6, 8):

Vectors (3, 4), (6, 8)
Vectors (3, 4), (6, 8)

The vector (3, 4) has a magnitude of 32+42=5\sqrt{3 ^2 + 4^2} = 5. The vector (6, 8) has a magnitude of 62+82=10\sqrt{6^2 + 8^2} = 10

The vectors have different sizes/lengths/magnitudes, but they have the same direction/angle: 53.13\approx 53.13^\circ.

Cosine similarity, a measure of the similarity between vectors that’s used in semantic search applications, is a measure of the direction of vectors. It completely ignores the magnitude:

Cosine Similarity=A.BAB \text{Cosine Similarity} = \frac{A.B}{||A||\cdot||B||}

That means, the dot product of AA and BB divided by the product of the magnitudes of AA and BB.

The (general) meaning of the dot product of two vectors

Dividing by the magnitudes normalizes away the length information

Given: (3, 4) and (6, 8):

Cosine similarity=3×6+4×85×10=1 \text{Cosine similarity} = \frac{3 \times 6 + 4 \times 8}{5 \times 10} = 1

Dividing by the product of the magnitudes constrains (normalizes) the result to [1,1][-1, 1].

The meaning of direction and magnitude in terms of semantic analysis of text

Tentatively, direction is a measure of “what is this text talking about” and magnitude is a measure of how emphatic the text is, or how much text there is. (That seems a little too convenient, but also kind of right.)

References

Khan Academy. “Vectors and notation.” Accessed on: January 14, 2026. https://www.khanacademy.org/math/multivariable-calculus/thinking-about-multivariable-function/x786f2022:vectors-and-matrices/a/vectors-and-notation-mvc .

Tags: