vector_norm#
- class saiunit.linalg.vector_norm(x, *, axis=None, keepdims=False, ord=2, **kwargs)#
Compute the vector norm of a vector or batch of vectors.
SaiUnit implementation of
numpy.linalg.vector_norm().- Parameters:
x (
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity) – N-dimensional input.axis (
int|tuple[int,...] |None) – Axis (or axes) along which to compute the norm. IfNone(default), x is flattened first.keepdims (
bool) – IfTrue, reduced axes are kept as size-1 dimensions (default:False).ord (
int|str) – Type of norm (default: 2). Seenumpy.linalg.norm()for available options.
- Returns:
out – Vector norm of x. Carries the same unit as x.
- Return type:
Array| saiunit.Quantity
Examples
>>> import saiunit as u >>> import jax.numpy as jnp Norm of a single vector: >>> x = jnp.array([1., 2., 3.]) * u.meter >>> u.linalg.vector_norm(x) 3.7416575 * meter Batch of vectors along axis 1: >>> x = jnp.array([[1., 2., 3.], ... [4., 5., 7.]]) * u.meter >>> u.linalg.vector_norm(x, axis=1) ArrayImpl([3.7416575, 9.48683262], dtype=float32) * meter