Norm (Taxicab Norm or Manhattan norm) | Norm (Euclidean norm) | Max Norm |
---|---|---|
The norm is calculated as the sum of the absolute vector values. | The norm is calculated as the square root of the sum of the squared vector values. | The max norm is calculated as returning the maximum value of the vector, hence the name. |
In effect, the norm is a calculation of the Manhattan distance from the origin of the vector space. | The L2 norm is also known as the Euclidean norm as it is calculated as the Euclidean distance from the origin. | |
The norm is often used when fitting machine learning algorithms as a regularization method, e.g. a method to keep the coefficients of the model small, and in turn, the model less complex. | Like the norm, the norm is often used when fitting machine learning algorithms as a regularization method, e.g. a method to keep the coefficients of the model small and, in turn, the model less complex. | Max norm is also used as a regularization in machine learning, such as on neural network weights, called max norm regularization. |
By far, the norm is more commonly used than other vector norms in machine learning. |
norm
- The norm of a vector can be calculated in
NumPy
using thenorm()
function with a parameter to specify the norm order, in this case1
.
# l1 norm of a vector
from numpy import array
from numpy.linalg import norm
a = array([1, 2, 3])
print(a) # [1 2 3]
l1 = norm(a, 1)
print(l1) # 6
Norm
- The norm of a vector can be calculated in
NumPy
using thenorm()
function with default parameters.
# l2 norm of a vector
from numpy import array
from numpy.linalg import norm
a = array([1, 2, 3])
print(a) # [1 2 3]
l2 = norm(a)
print(l2) # 3.7416573867739413
Max Norm
The max norm of a vector can be calculated in NumPy
using the norm()
function with the order parameter set to inf
.
# max norm of a vector
from numpy import inf
from numpy import array
from numpy.linalg import norm
a = array([1, 2, 3])
print(a) # [1 2 3]
maxnorm = norm(a, inf)
print(maxnorm) # 3.0