vectorNorm#

swordfish.function.vectorNorm()#

Compute a matrix or vector norm. Note that it’s not recommended to use vectorNorm in SQL statements.

Parameters:
  • x (Constant) – A vector or matrix of any numeric type except DECIMAL. It cannot be empty.

  • ord (Constant, optional) –

    An INT, STRING or floating-point scalar indicating the order of norm, by default DFLT.

    Note

    When ord is a string, it must be: ‘inf’, ‘-inf’, ‘nuc’, or ‘fro’.

    When ord is less than 1, the result is technically not a mathematical “norm”, but it may still be useful for various numerical purposes.

    The following describes the method for computing the norm based on different x and ord:

    ord

    norm for vectors

    norm for matrices

    None

    2-norm

    Frobenius norm

    0

    sum(x != 0)

    &#45

    -1

    sum(abs(x)^ord)^(1/ord)

    min(sum(abs(x), axis=0))

    1

    sum(abs(x)^ord)^(1/ord)

    max(sum(abs(x), axis=0))

    -2

    sum(abs(x)^ord)^(1/ord)

    2-norm (largest sing. value)

    2

    sum(abs(x)^ord)^(1/ord)

    smallest singular value

    inf

    max(abs(x))

    max(sum(abs(x), axis=1))

    -inf

    min(abs(x))

    min(sum(abs(x), axis=1))

    nuc

    &#45

    nuclear norm

    fro

    &#45

    Frobenius norm

    other

    sum(abs(x)^ord)^(1/ord)

    &#45

  • axis (Constant, optional) –

    An integer vector or scalar indicating the direction along which to compute the norm, by default DFLT. It cannot contain empty elements.

    • When x is a vector, axis can only be 0.

    • When x is a matrix, axis:

    • Has a length of no more than 2.

    • Cannot contain duplicate elements.

    • Has elements with values of 0 or 1.

  • keepDims (Constant, optional) – A boolean scalar indicating whether the returned result should maintain the same form as x, by default DFLT.

Returns:

An INT, LONG, or DOUBLE scalar, vector, or matrix.

Return type:

Constant