Returns an array whose elements are normalized based on the specified p norm.
Syntax
array_normalize(array, p)
This function is equivalent to TRANSFORM(array, v -> v / REDUCE(array, 0, (a, v) -> a + POW(ABS(v), p), a -> POW(a, 1 / p))
. However, the REDUCE
function is called only once.
Parameters
array: an input array. The elements in the array can be of only the FLOAT or DOUBLE type.
p: the p norm of the array.
Return value
An array whose elements are normalized based on the specified p norm is returned.
If the array is null or contains null elements, null is returned.
If the
p=0
condition is met, the original array is returned. If thep<0
condition is met, an error is returned.
Examples
SELECT array_normalize(array(10.0, 20.0, 50.0), 1.0);
The following result is returned:
[0.125, 0.25, 0.625]
Related functions
ARRAY_NORMALIZE is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.