turicreate.toolkits.distances.manhattan

turicreate.toolkits.distances.manhattan(x, y)

Compute the Manhattan distance between between two dictionaries or two lists of equal length. Suppose x and y each contain \(d\) variables:

\[D(x, y) = \sum_i^d |x_i - y_i|\]
Parameters:
x : dict or list

First input vector.

y : dict or list

Second input vector.

Returns:
out : float

Manhattan distance between x and y.

Notes

  • If the input vectors are in dictionary form, keys missing in one of the two dictionaries are assumed to have value 0.
  • Manhattan distance is also known as “city block” or “taxi cab” distance.

References

Examples

>>> tc.distances.manhattan([1, 2, 3], [4, 5, 6])
9.0
...
>>> tc.distances.manhattan({'a': 2, 'c': 4}, {'b': 3, 'c': 12})
13.0