What is the arctanh function in NumPy?
In NumPy, a library of the high-level programming language Python, we can use the arctanh function to calculate the inverse hyperbolic tangent of a set of values.
The numpy library must be imported to use the arctanh function:
import numpy as np
Syntax
np.arctanh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])= <ufunc 'arctanh'>
A universal function (
ufunc) is a function that operates on ndarrays in an element-by-element fashion. Thearctanhmethod is a universal function.
Arguments
The arctanh function only accepts the following arguments:
x: An array-like structure on the contents of which thearctanhfunction will be applied.out(optional): The function’s output is stored at this location.where(optional): If setTrue, a universal function is calculated at this position.casting(optional): This enables the user to decide how the data will be cast. If set assame_kind, safe casting will take place.order(optional): This determines the memory layout of the output. For example, if set as K, the function reads data in the order they are written in memory.dtype(optional): This is the data type of the array.subok(optional): To pass subclasses,subokmust be set asTrue.
Return value
The arctanh function returns an angle of type float whose imaginary part lies in [-pi/2,pi/2]. For imaginary input, it has branch cuts [-1,inf] and [1,inf].
If a number cannot be represented as a real number or infinity, it returns NaN, and the invalid floating point error flag is set.
For real input, the
arctanhfunction returns real input!
Example
The following example demonstrates how the arctanh function responds to complex, real, or invalid inputs.
To use the arctanh function, we first import the numpy library, which contains it.
import numpy as npprint("Complex input:", np.arctanh(3+2j))print("Invalid input:", np.arctanh(5))print("Real input:", np.arctanh(.5))
Free Resources