tanh

tanh(x, out=None, **kwargs)

Compute hyperbolic tangent element-wise. Equivalent to np.sinh(x)/np.cosh(x).

Parameters:
x : ndarray or scalar.

Input array.

out : ndarray or None

A location into which the result is stored. If provided, it must have a shape that the inputs fill into. If not provided or None, a freshly-allocated array is returned. The dtype of the output and input must be the same.

Returns:
y : ndarray or scalar

The corresponding hyperbolic tangent values.

Notes

If out is provided, the function writes the result into it, and returns a reference to out. (See Examples) - input x does not support complex computation (like imaginary number) >>> np.tanh(np.pi*1j) TypeError: type <type ‘complex’> not supported

Examples

>>> np.tanh(np.array[0, np.pi]))
array([0.       , 0.9962721])
>>> np.tanh(np.pi)
0.99627207622075
>>> # Example of providing the optional output parameter illustrating
>>> # that what is returned is a reference to said parameter
>>> out1 = np.array(1)
>>> out2 = np.tanh(np.array(0.1), out1)
>>> out2 is out1
True