Aliases:
tf.linalg.norm
tf.norm
tf.norm(
tensor,
ord='euclidean',
axis=None,
keepdims=None,
name=None,
keep_dims=None
)
Defined in tensorflow/python/ops/linalg_ops.py
.
Computes the norm of vectors, matrices, and tensors. (deprecated arguments)
This function can compute several different vector norms (the 1-norm, the Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Args:
tensor
:Tensor
of typesfloat32
,float64
,complex64
,complex128
ord
: Order of the norm. Supported values are 'fro', 'euclidean',1
,2
,np.inf
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
,2
,np.inf
are supported. See the description ofaxis
on how to compute norms for a batch of vectors or matrices stored in a tensor.axis
: Ifaxis
isNone
(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 tonorm(reshape(tensor, [-1]), ord=ord)
. Ifaxis
is a Python integer, the input is considered a batch of vectors, andaxis
determines the axis intensor
over which to compute vector norms. Ifaxis
is a 2-tuple of Python integers it is considered a batch of matrices andaxis
determines the axes intensor
over 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, passaxis=[-2,-1]
instead ofaxis=None
to make sure that matrix norms are computed.keepdims
: If True, the axis indicated inaxis
are kept with size 1. Otherwise, the dimensions inaxis
are removed from the output shape.name
: The name of the op.keep_dims
: Deprecated alias forkeepdims
.
Returns:
output
: ATensor
of the same type as tensor, containing the vector or matrix norms. Ifkeepdims
is True then the rank of output is equal to the rank oftensor
. Otherwise, ifaxis
is none the output is a scalar, ifaxis
is an integer, the rank ofoutput
is one less than the rank oftensor
, ifaxis
is a 2-tuple the rank ofoutput
is two less than the rank oftensor
.
Raises:
ValueError
: Iford
oraxis
is invalid.
Numpy Compatibility
Mostly equivalent to numpy.linalg.norm.
Not supported: ord <= 0, 2-norm for matrices, nuclear norm.
Other differences:
a) If axis is None
, treats the flattened tensor
as a vector
regardless of rank.
b) Explicitly supports 'euclidean' norm as the default, including for
higher order tensors.