Minkowski Distance

The Minkowski Distance is a generalized distance metrics that is used to measure the distance/similarity between two vectors.

Mathematically, is it represented as:

$$ (\sum_{i=1}^n | x_i - y_i |^p)^{\frac {1}{p}} $$

Notices that the $p$ parameter provides the generalization such that if $p=1$, then the distance metrics is Manhattan Distance. If $p=2$, then the distance is Euclidean.

Implementation in Python

In the example below, we generate a function for Minkowki Distance and compute some distance with $p=2$

import numpy as np

def minkowski(x_vector, y_vector, p):
    return (np.sum((x_vector - y_vector)**p))**(1/p)
a = np.array([6.3, 4.1])
b = np.array([3.2, 1.7])

minkowski(a, b, 2)
3.920459156782531