Skip to content

l1_norm()

Function Description

The l1_norm function is used to calculate the l1/Manhattan/TaxiCab norm. l1 norm is obtained by summing the absolute values ​​of vector elements.

You can use the l1 norm to calculate the l1 distance.

l1_distance(a,b) = l1_norm(a-b)

This calculation method is also applicable to calculating the l2 distance from l2_Norm.

Function Syntax

> SELECT l1_norm(vector) AS result FROM table_name;

Example

drop table if exists vec_table;
create table vec_table(a int, b vecf32(3), c vecf64(3));
insert into vec_table values(1, "[1,2,3]", "[4,5,6]");
mysql> select * from vec_table;
+-------+--------------------------+
| a | b | c |
+-------+--------------------------+
| 1 | [1, 2, 3] | [4, 5, 6] |
+-------+--------------------------+
1 row in set (0.00 sec)

mysql> select l1_norm(b) from vec_table;
+----------------+
| l1_norm(b) |
+----------------+
| 6 |
+----------------+
1 row in set (0.00 sec)