jax.numpy.hypot#
- jax.numpy.hypot(x1, x2, /)[源代码]#
返回给定直角三角形的直角边的元素级斜边。
numpy.hypot
的 JAX 实现。- 参数:
x1 (ArrayLike) – 标量或数组。指定直角三角形的一条直角边。
complex
dtype 不受支持。x2 (ArrayLike) – 标量或数组。指定直角三角形的另一条直角边。
complex
dtype 不受支持。x1
和x2
必须具有相同的形状或广播兼容。
- 返回:
一个数组,包含给定直角三角形的直角边
x1
和x2
的斜边,并提升为非精确 dtype。- 返回类型:
注意
jnp.hypot
是计算jnp.sqrt(x1 ** 2 + x2 **2)
的一种数值上更稳定的方法。示例
>>> 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)