VECTOR_SQUARED_EUCLIDEAN_DISTANCE
Returns the squared Euclidean distance, or squared L2 distance between two vectors. The squared Euclidean distance measures how far apart two vectors based on the size of their differences, without considering direction. By squaring the difference, it emphasizes larger differences, which can help in finding outliers or large deviations.
Syntax
VECTOR_SQUARED_EUCLIDEAN_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 squared Euclidean distance between two vectors:
SELECT VECTOR_SQUARED_EUCLIDEAN_DISTANCE([1, 2], [3, 4]) AS distance;
distance (DOUBLE) |
---|
8 |
The following example returns the squared Euclidean distance between two identical vectors:
SELECT VECTOR_SQUARED_EUCLIDEAN_DISTANCE([1, 1], [1, 1]) AS distance;
distance (DOUBLE) |
---|
0 |
The following example returns the squared Euclidean distance between two vectors that are very far apart:
SELECT VECTOR_SQUARED_EUCLIDEAN_DISTANCE([1, 1], [10, 10]) AS distance;
distance (DOUBLE) |
---|
162 |