VECTOR_MANHATTAN_DISTANCE
Returns the Manhattan, or L1 distance, between two vectors. The Manhattan distance measures the total distance by moving strictly along orthogonal axes, similar to navigating streets in a city grid. It is calculated as the sum of absolute differences between corresponding elements of two vectors.
Syntax
VECTOR_MANHATTAN_DISTANCE(<array>, <array>)
Parameters
Parameter | Description | Supported input types |
---|---|---|
<array> | The first array used in the distance calculation. | Any array of numeric data types. |
<array> | The second array used in the distance calculation. | Any array of numeric data types. |
Notes
Both input array
arguments must have the same number of elements.
Return Type
DOUBLE
Examples
The following example returns the Manhattan distance between two vectors:
SELECT VECTOR_MANHATTAN_DISTANCE([1, 4], [3, 2]) AS distance;
In the previous example, the Manhattan distance is calculated as the sum of absolute differences: |3 - 1| + |2 - 4| = 4.
distance (DOUBLE) |
---|
4 |