Length or Size of a Vector
The Pythagorus theorem is a generalized theorem that calcutates the distance between two points that are perpendicular to each other like a right-angle triangle. The theorem is mathematically represented as:
$$ c = \sqrt{ a^2 + b^2} $$
where $a$ and $b$ are perpendicular sides of a triangle.
It turns out the this formula is a lot more general and can be used to calculate the length/size at n-dimensions. We can in fact think of the pythagorus theorem as 2-d case of calculating the size of vector.
More broadly, the size of a vector is equal to the square root of the sum of the squares of the vector elements.
Mathematically, we represent the length of a vectors as:
$$ ||r|| = \sqrt{r_1^2 + r_2^2 + ... + r_n^2} $$
where $r$ is a vector of n-dimension.
Implementation in Numpy with np.linalg.norm
Suppose $r$ is a three-dimensions vector with values 2, 3 and 4. What is the size of $r$?
$$ r = \begin{bmatrix} 2 \\ 3 \\ 4 \end{bmatrix} $$
$$ ||r|| = \sqrt{ 2^2 + 3^2 + 4^2 } = \sqrt{ 4 + 9 + 16} = \sqrt{ 29 } \approx 5.4 $$
In numpy, $np.linalg.norm$ returns the L2 Norm which is the size of the vector
import numpy as np
sample_vect = np.array([2, 3, 4])
np.linalg.norm(sample_vect)