Vector Length (Magnitude or Norm)
In geometry, we often want to measure the length of a line segment. In linear algebra, this concept of size is extended to vectors and is called length, magnitude, or norm. In this lesson, we will see how algebra and geometry shake hands through the familiar Pythagorean theorem to define the norm of a vector, and how to compute it in Python.
1. The Algebraic Definition
Algebraically, the length of a vector (written using double bars: ) is computed by taking the square root of the dot product of the vector with itself:
For an -dimensional vector , this formula sums the squared values of every component and takes the square root:
Sanity Check: Don't Forget the Square Root! A common mistake when computing vector norms is forgetting to take the square root at the end. Forgetting the root leaves you with the squared norm . In coordinates, a vector of length would suddenly have an apparent size of $13$, failing basic visual and geometric scale checks!
2. The Geometric Perspective (Pythagorean Connection)
To understand why the algebraic norm works, let's explore it geometrically in a 2D Cartesian plane.
Let's define a vector:
If we plot in its standard position (starting at the origin $(0,0)$ and ending at coordinate $(2,3)$), it forms the diagonal hypotenuse of a right-angled triangle:
- The horizontal leg of the triangle lies along the -axis and has a length of $2$ units.
- The vertical leg of the triangle is parallel to the -axis and has a length of $3$ units.

According to the Pythagorean Theorem (), the squared length of the hypotenuse is:
Substituting our vector components:
Looking at the graph, this value makes intuitive sense: since one side is $3$ units and the other is $2$ units, the hypotenuse should be slightly longer than the longest leg ($3$).
3. Algebra and Geometry hand-in-hand
By computing the algebraic norm of , we observe the exact same arithmetic:
The algebraic dot product of a vector with itself is literally squaring each individual element and summing them together. Therefore, computing the vector norm is simply the multi-dimensional generalization of the Pythagorean Theorem!
While right triangles are easy to draw and visualize in $2$D (and $3$D), this algebraic definition generalizes seamlessly to vectors of any dimension , where drawing triangles is no longer possible.
There are several ways to compute the norm of a vector in NumPy, ranging from manual computations mirroring the algebraic dot product formulas, to utilizing the highly optimized linear algebra solver.
import numpy as np
# Define a 6D vector
v = np.array([ 1, 2, 3, 4, 5, 6 ])
# Method 1: Manual sum of element-wise multiplication + square root
norm_elementwise = np.sqrt( sum( np.multiply(v, v) ) )
# Method 2: Manual dot product + square root
norm_dotproduct = np.sqrt( np.dot(v, v) )
# Method 3: NumPy's optimized Norm Solver
norm_numpy = np.linalg.norm(v)
print(f"Vector: {v}")
print(f"1. Element-wise Sum: {norm_elementwise:.6f}")
print(f"2. Dot Product: {norm_dotproduct:.6f}")
print(f"3. np.linalg.norm: {norm_numpy:.6f}")
print(f"All methods match? {np.isclose(norm_elementwise, norm_numpy) and np.isclose(norm_dotproduct, norm_numpy)}")Vector: [1 2 3 4 5 6]
1. Element-wise Sum: 9.539392
2. Dot Product: 9.539392
3. np.linalg.norm: 9.539392
All methods match? TrueKey Takeaways
- Definition: The vector norm (length) is the square root of the dot product of a vector with itself: .
- Generalization: The algebraic norm generalizes the $2$D Pythagorean theorem () to high-dimensional spaces ().
- Best Practice: In python, always prefer
np.linalg.norm()for production code as it leverages highly-vectorized underlying algebra libraries.