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,
axisspecifies the axis (dimension) along which to compute vector norms. If an n-tuple,axisspecifies 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 byaxismust 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 byaxismust 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
axisisNone, the returned array must be a zero-dimensional array containing a vector norm. Ifaxisis a scalar value (intorfloat), the returned array must have a rank which is one less than the rank ofx. Ifaxisis an-tuple, the returned array must have a rank which isnless than the rank ofx. The returned array must have a floating-point data type determined by Type Promotion Rules.