Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé
Module « numpy.linalg »

Fonction vector_norm - module numpy.linalg

Signature de la fonction vector_norm

def vector_norm(x, /, *, axis=None, keepdims=False, ord=2) 

Description

help(numpy.linalg.vector_norm)

Computes the vector norm of a vector (or batch of vectors) ``x``.

This function is Array API compatible.

Parameters
----------
x : array_like
    Input array.
axis : {None, int, 2-tuple of ints}, optional
    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. If ``None``,
    the vector norm must be computed over all array values (i.e.,
    equivalent to computing the vector norm of a flattened array).
    Default: ``None``.
keepdims : bool, optional
    If this is set to True, the axes which are normed over are left in
    the result as dimensions with size one. Default: False.
ord : {int, float, inf, -inf}, optional
    The order of the norm. For details see the table under ``Notes``
    in `numpy.linalg.norm`.

See Also
--------
numpy.linalg.norm : Generic norm function

Examples
--------
>>> from numpy import linalg as LA
>>> a = np.arange(9) + 1
>>> a
array([1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> b = a.reshape((3, 3))
>>> b
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

>>> LA.vector_norm(b)
16.881943016134134
>>> LA.vector_norm(b, ord=np.inf)
9.0
>>> LA.vector_norm(b, ord=-np.inf)
1.0

>>> LA.vector_norm(b, ord=0)
9.0
>>> LA.vector_norm(b, ord=1)
45.0
>>> LA.vector_norm(b, ord=-1)
0.3534857623790153
>>> LA.vector_norm(b, ord=2)
16.881943016134134
>>> LA.vector_norm(b, ord=-2)
0.8058837395885292



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé