The ML.LP_NORM function

This document describes the ML.LP_NORM scalar function, which lets you compute the Lp norm for a vector, where p is the degree.

Syntax

ML.LP_NORM(vector, degree)

Arguments

ML.LP_NORM has the following arguments:

Output

ML.LP_NORM returns a FLOAT64 value that represents the Lp norm for the vector. Returns NULL if vector is NULL.

Example

The following example gets the Euclidean norm for vectors consisting of ARRAY<FLOAT64> values:

  1. Create the table t1:

    CREATE TABLE mydataset.t1
    (
      v1 ARRAY<FLOAT64>,
      v2 ARRAY<FLOAT64>
    )
    
  2. Populate t1:

    INSERT mydataset.t1 (v1,v2)
    VALUES ([4.1,0.5,1.0], [3.0,0.0,2.5])
    
  3. Calculate the Euclidean norm for v1 and v2:

    SELECT v1, ML.LP_NORM(v1, 2.0) AS v1_norm, v2, ML.LP_NORM(v2, 2.0) AS v2_norm
    FROM mydataset.t1;
    

    This query produces the following output:

    +---------------------------+-----+-------------------+
    | v1  | v1_norm             | v2  | v2_norm           |
    +---------------------------+-----+-------------------+
    | 4.1 | 4.2497058721751557  | 3.0 | 3.905124837953327 |
    +-----|                     |-----|                   |
    | 0.5 |                     | 0.0 |                   |
    +-----|                     |-----+                   |
    | 1.0 |                     | 2.5 |                   |
    +---------------------------+-----+-------------------+
    

What's next