dpnp.linalg.vector_norm

dpnp.linalg.vector_norm(x, /, *, axis=None, keepdims=False, ord=2)[source]

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

This function is Array API compatible.

For full documentation refer to numpy.linalg.vector_norm.

Parameters:
  • x ({dpnp.ndarray, usm_ndarray}) -- Input array.

  • axis ({None, int, n-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. With this option the result will broadcast correctly against the original x. Default: False.

  • ord ({int, float, inf, -inf, 'fro', 'nuc'}, optional) -- The order of the norm. For details see the table under Notes section in dpnp.linalg.norm. Default: 2.

Returns:

out -- Norm of the vector.

Return type:

dpnp.ndarray

See also

dpnp.linalg.norm

Generic norm function.

Examples

>>> import dpnp as np
>>> 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]])
>>> np.linalg.vector_norm(b)
array(16.88194302)
>>> np.linalg.vector_norm(b, ord=np.inf)
array(9.)
>>> np.linalg.vector_norm(b, ord=-np.inf)
array(1.)
>>> np.linalg.vector_norm(b, ord=1)
array(45.)
>>> np.linalg.vector_norm(b, ord=-1)
array(0.35348576)
>>> np.linalg.vector_norm(b, ord=2)
array(16.881943016134134)
>>> np.linalg.vector_norm(b, ord=-2)
array(0.8058837395885292)