vector_norm¶
- vector_norm(x: array, /, *, axis: int | Tuple[int, ...] | None = None, keepdims: bool = False, ord: int | float | ~typing.Literal[inf, -inf] = 2) array ¶
Computes the vector norm of a vector (or batch of vectors)
x
.- Parameters:
x (array) – input array. Should have a floating-point data type.
axis (Optional[Union[int, Tuple[int, ...]]]) – If an integer,
axis
specifies the axis (dimension) along which to compute vector norms. If an n-tuple,axis
specifies the axes (dimensions) along which to compute batched vector norms. IfNone
, the vector norm must be computed over all array values (i.e., equivalent to computing the vector norm of a flattened array). Negative indices must be supported. Default:None
.keepdims (bool) – If
True
, the axes (dimensions) specified byaxis
must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, ifFalse
, the axes (dimensions) specified byaxis
must not be included in the result. Default:False
.ord (Union[int, float, Literal[inf, -inf]]) –
order of the norm. The following mathematical norms must be supported:
ord
description
1
L1-norm (Manhattan)
2
L2-norm (Euclidean)
inf
infinity norm
(int,float >= 1)
p-norm
The following non-mathematical “norms” must be supported:
ord
description
0
sum(a != 0)
-1
1./sum(1./abs(a))
-2
1./sqrt(sum(1./abs(a)**2))
-inf
min(abs(a))
(int,float < 1)
sum(abs(a)**ord)**(1./ord)
Default:
2
.
- Returns:
out (array) – an array containing the vector norms. If
axis
isNone
, the returned array must be a zero-dimensional array containing a vector norm. Ifaxis
is a scalar value (int
orfloat
), the returned array must have a rank which is one less than the rank ofx
. Ifaxis
is an
-tuple, the returned array must have a rank which isn
less than the rank ofx
. The returned array must have a floating-point data type determined by Type Promotion Rules.