l2_norm#
- class braintools.metric.l2_norm(predictions, targets=None, axis=None)#
Compute the L2 norm of the difference between predictions and targets.
- Parameters:
predictions (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – A vector of arbitrary shape[...].targets (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – A vector with the same shape aspredictions(shape equality is asserted; no broadcasting). If not provided then it is assumed to be a vector of zeros.axis (
int|tuple[int,...] |None) – The dimensions to reduce. If None, the norm is computed over the whole (flattened) array and reduced to a scalar.
- Returns:
The L2 norm of the differences along
axis.- Return type:
Array|ndarray|bool|number|bool|int|float|complex|Quantity
Examples
>>> import jax.numpy as jnp >>> import braintools >>> predictions = jnp.array([3.0, 4.0]) >>> braintools.metric.l2_norm(predictions) Array(5., dtype=float32)