Compute the Hyperbolic tangent in Python


To compute the Hyperbolic tangent, use the numpy.tanh() method in Python Numpy. Equivalent to np.sinh(x)/np.cosh(x) or -1j * np.tan(1j*x). Returns the corresponding hyperbolic tangent values. This is a scalar if x is a scalar. The 1st parameter, x is input array. The 2nd and 3rd parameters are optional.

The 2nd parameter is an ndarray, 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.

The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value.

Steps

At first, import the required library −

import numpy as np

Get the Trigonometric Hyperbolic tangent. Find tanh −

print("\nResult...",np.tanh(np.pi*1j))

Finding tanh 90 degrees −

print("\nResult...",np.tanh(np.pi/2.))

Finding tanh 60 degrees −

print("\nResult...",np.tanh(np.pi/3.))

Finding tanh 45 degrees −

print("\nResult...",np.tanh(np.pi/4.))

Finding tanh 30 degrees −

print("\nResult...",np.tanh(np.pi/6.))

Finding tanh 0 degrees −

print("\nResult...",np.tanh(0))

Example

import numpy as np

# To compute the Hyperbolic tangent, use the numpy.tanh() method in Python Numpy
# Equivalent to np.sinh(x)/np.cosh(x) or -1j * np.tan(1j*x).
# Returns the corresponding hyperbolic tangent values. This is a scalar if x is a scalar.

print("Get the Trigonometric Hyperbolic tangent...")

# find tanh
print("\nResult...",np.tanh(np.pi*1j))

# finding tanh 90 degrees
print("\nResult...",np.tanh(np.pi/2.))

# finding tanh 60 degrees
print("\nResult...",np.tanh(np.pi/3.))

# finding tanh 45 degrees
print("\nResult...",np.tanh(np.pi/4.))

# finding tanh 30 degrees
print("\nResult...",np.tanh(np.pi/6.))

# finding tanh 0 degrees
print("\nResult...",np.tanh(0))

Output

Get the Trigonometric Hyperbolic tangent...

Result... -1.2246467991473532e-16j

Result... 0.9171523356672744

Result... 0.7807144353592677

Result... 0.6557942026326724

Result... 0.4804727781564516

Result... 0.0

Updated on: 24-Feb-2022

311 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements