In comparison to the Euclidian distance the Manhattan distance is calculated by simply adding up the absolute values of the differences in each dimension. It is also known as the L1 norm or L1 metric. In analogy to the above example the Manhattan distance of two two-dimensional points can be calculated like this:

d = |x_2 - x_1| + |y_2 - y_1|,

where the vertical lines || are used to denote the absolute values of the differences. The Manhattan distance for two three-dimensional points can meanwhile be calculated like this:

d = |x_2 - x_1| + |y_2 - y_1| + |z_2 - z_1|.

The Manhattan distance can be further generalized to higher dimensions by simply adding more terms for each dimension. However, when using a high-level language such as Python the actual computation should be done using vectorized operations using libraries like NumPy. This is because for large inputs such operations will be significantly faster than a one-to-one implementation of the above expressions in Python.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence