tanh

paddle. tanh ( x: Tensor, name: str | None = None ) Tensor [source]

Tanh Activation Operator.

\[out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
Parameters
  • x (Tensor) – Input of Tanh operator, an N-D Tensor, with data type bfloat16, float32, float64, float16, uint8, int8, int16, int32, int64.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Output of Tanh operator, a Tensor with same data type and shape as input

(integer types are autocasted into float32).

Examples

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.tanh(x)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.37994900, -0.19737528,  0.09966799,  0.29131261])