NumPy Tutorial NumPy Statistics NumPy References

NumPy - tanh() function



The NumPy tanh() function is used to calculate hyperbolic tangent of a value. The hyperbolic tangent of x is defined as:

tanh

where e is an Euler's number.

Syntax

numpy.tanh(a, out=None)

Parameters

a Required. Specify array (array_like) containing elements, of which the hyperbolic tangent is calculated.
out Optional. Specify a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.

Return Value

Returns the hyperbolic tangent of each element in a.

Example:

In the example below, numpy tanh() function is used to calculate the hyperbolic tangent of each element present in array Arr.

import numpy as np

Arr = np.array([1, 2, 3, 4])

print("The hyperbolic tangent of values:")
print(np.tanh(Arr))

The output of the above code will be:

The hyperbolic tangent of values:
[ 0.76159416  0.96402758  0.99505475  0.9993293 ]

❮ NumPy - Functions

5