jax.numpy.tanh#
- jax.numpy.tanh(x, /)[source]#
Calculate element-wise hyperbolic tangent of input.
JAX implementation of
numpy.tanh
.The hyperbolic tangent is defined by:
\[tanh(x) = \frac{sinh(x)}{cosh(x)} = \frac{e^x - e^{-x}}{e^x + e^{-x}}\]- Parameters:
x (ArrayLike) – input array or scalar.
- Returns:
An array containing the hyperbolic tangent of each element of
x
, promoting to inexact dtype.- Return type:
Note
jnp.tanh
is equivalent to computing-1j * jnp.tan(1j * x)
.See also
jax.numpy.sinh()
: Computes the element-wise hyperbolic sine of the input.jax.numpy.cosh()
: Computes the element-wise hyperbolic cosine of the input.jax.numpy.arctanh()
: Computes the element-wise inverse of hyperbolic tangent of the input.
Examples
>>> x = jnp.array([[-1, 0, 1], ... [3, -2, 5]]) >>> with jnp.printoptions(precision=3, suppress=True): ... jnp.tanh(x) Array([[-0.762, 0. , 0.762], [ 0.995, -0.964, 1. ]], dtype=float32) >>> with jnp.printoptions(precision=3, suppress=True): ... -1j * jnp.tan(1j * x) Array([[-0.762+0.j, 0. -0.j, 0.762-0.j], [ 0.995-0.j, -0.964+0.j, 1. -0.j]], dtype=complex64, weak_type=True)
For complex-valued input:
>>> with jnp.printoptions(precision=3, suppress=True): ... jnp.tanh(2-5j) Array(1.031+0.021j, dtype=complex64, weak_type=True) >>> with jnp.printoptions(precision=3, suppress=True): ... -1j * jnp.tan(1j * (2-5j)) Array(1.031+0.021j, dtype=complex64, weak_type=True)