jax.numpy.hypot — JAX documentation (original) (raw)

jax.numpy.hypot#

jax.numpy.hypot(x1, x2, /)[source]#

Return element-wise hypotenuse for the given legs of a right angle triangle.

JAX implementation of numpy.hypot.

Parameters:

Returns:

An array containing the hypotenuse for the given given legs x1 and x2of a right angle triangle, promoting to inexact dtype.

Return type:

Array

Note

jnp.hypot is a more numerically stable way of computingjnp.sqrt(x1 ** 2 + x2 **2).

Examples

jnp.hypot(3, 4) Array(5., dtype=float32, weak_type=True) x1 = jnp.array([[3, -2, 5], ... [9, 1, -4]]) x2 = jnp.array([-5, 6, 8]) with jnp.printoptions(precision=3, suppress=True): ... jnp.hypot(x1, x2) Array([[ 5.831, 6.325, 9.434], [10.296, 6.083, 8.944]], dtype=float32)