e3x.ops.safe.normalize_and_return_norm

e3x.ops.safe.normalize_and_return_norm(x, axis=None, keepdims=False)[source]

Normalize x using the L2-norm along the specified axis and return its norm.

If x has a norm of almost zero, it is left unnormalized, because normalization becomes numerically unstable.

Parameters:
  • x (<class 'Float[Array, '...']'>) – Input array.

  • axis (Union[int, Tuple[int, ...], None], default: None) – Axis or axes along which the L2-norm is computed. The default, axis=None, will compute the norm of all elements of the input array (as if it was one large vector). If axis is negative it counts from the last to the first axis.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced for computing the norm are left in the norm result as dimensions with size one.

Return type:

Tuple[Float[Array, '...'], Float[Array, '...']]

Returns:

A tuple consisting of the normalized array and its norm.