tf.keras.ops.norm  |  TensorFlow v2.16.1 (original) (raw)

tf.keras.ops.norm

Matrix or vector norm.

View aliases

Main aliases

tf.keras.ops.linalg.norm

tf.keras.ops.norm(
    x, ord=None, axis=None, keepdims=False
)

This function is able to return one of eight different matrix norms, or one of an infinite number of vector norms (described below), depending on the value of the ord parameter.

Args
x Input tensor.
ord Order of the norm (see table under Notes). The default is None.
axis If axis is an integer, it specifies the axis of x along which to compute the vector norms. If axis is a 2-tuple, it specifies the axes that hold 2-D matrices, and the matrix norms of these matrices are computed.
keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one.
Note
For values of ord < 1, the result is, strictly speaking, not a mathematical 'norm', but it may still be useful for various numerical purposes. The following norms can be calculated: For matrices: ord=None: Frobenius norm ord="fro": Frobenius norm ord="nuc": nuclear norm ord=np.inf: max(sum(abs(x), axis=1)) ord=-np.inf: min(sum(abs(x), axis=1)) ord=0: not supported ord=1: max(sum(abs(x), axis=0)) ord=-1: min(sum(abs(x), axis=0)) ord=2: 2-norm (largest sing. value) ord=-2: smallest singular value other: not supported For vectors: ord=None: 2-norm ord="fro": not supported ord="nuc": not supported ord=np.inf: max(abs(x)) ord=-np.inf: min(abs(x)) ord=0: sum(x != 0) ord=1: as below ord=-1: as below ord=2: as below ord=-2: as below other: sum(abs(x)**ord)**(1./ord)
Returns
Norm of the matrix or vector(s).

Example:

x = keras.ops.reshape(keras.ops.arange(9, dtype="float32") - 4, (3, 3)) keras.ops.linalg.norm(x) 7.7459664

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.

Last updated 2024-06-07 UTC.