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:
x1 (ArrayLike) – scalar or array. Specifies one of the legs of right angle triangle.
complex
dtype are not supported.x2 (ArrayLike) – scalar or array. Specifies the other leg of right angle triangle.
complex
dtype are not supported.x1
andx2
must either have same shape or be broadcast compatible.
- Returns:
An array containing the hypotenuse for the given given legs
x1
andx2
of a right angle triangle, promoting to inexact dtype.- Return type:
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)