tf.norm(tensor, ord='euclidean', axis=None, keep_dims=False, name=None)
See the guide: Math > Matrix Math Functions
Computes the norm of vectors, matrices, and tensors.
This function can compute 3 different matrix norms (Frobenius, 1-norm, and inf-norm) and up to 9218868437227405311 different vectors norms.
ord: Order of the norm. Supported values are 'fro', 'euclidean',
and any positive real number yielding the corresponding p-norm. Default is 'euclidean' which is equivalent to Frobenius norm iftensor
is a matrix and equivalent to 2-norm for vectors. Some restrictions apply, a) The Frobenius normfro
is not defined for vectors, b) If axis is a 2-tuple (matrix-norm), only 'euclidean', 'fro',1
are supported. See the description ofaxis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
None(the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e.
norm(tensor, ord=ord)is equivalent to
norm(reshape(tensor, [-1]), ord=ord). If
axisis a Python integer, the input is considered a batch of vectors, and
axist determines the axis in
tensorover which to compute vector norms. If
axisis a 2-tuple of Python integers it is considered a batch of matrices and
axisdetermines the axes in
tensorover which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass
axis=Noneto make sure that matrix norms are computed.
keep_dims: If True, the axis indicated in
axisare kept with size 1. Otherwise, the dimensions in
axisare removed from the output shape.
name: The name of the op.
Tensorof the same type as tensor, containing the vector or matrix norms. If
keep_dimsis True then the rank of output is equal to the rank of
tensor. Otherwise, if
axisis none the output is a scalar, if
axisis an integer, the rank of
outputis one less than the rank of
axisis a 2-tuple the rank of
outputis two less than the rank of
Mostly equivalent to numpy.linalg.norm.
Not supported: ord <= 0, 2-norm for matrices, nuclear norm.
a) If axis is
None, treats the the flattened
tensor as a vector
regardless of rank.
b) Explicitly supports 'euclidean' norm as the default, including for
higher order tensors.