NumPy arcsinh()

The numpy.arcsinh() function computes the inverse hyperbolic sine (also known as the area hyperbolic sine) of each element in an input array.

Syntax

</>
Copy
numpy.arcsinh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)

Parameters

ParameterTypeDescription
xarray_likeInput array containing values for which the inverse hyperbolic sine is computed.
outndarray, None, or tuple of ndarray and None, optionalOptional output array where the result is stored. If None, a new array is created.
wherearray_like, optionalBoolean mask specifying which elements to compute. Elements where where=False retain their original value.
castingstr, optionalDefines the casting behavior when computing the function.
orderstr, optionalMemory layout order of the output array.
dtypedata-type, optionalDefines the data type of the output array.
subokbool, optionalDetermines if subclasses of ndarray are preserved in the output.

Return Value

Returns an array with the inverse hyperbolic sine values of the input elements. If the input is a scalar, a scalar is returned.


Examples

1. Computing arcsinh of a Single Value

Here, we compute the inverse hyperbolic sine of a single value.

</>
Copy
import numpy as np

# Define a single value
value = 1.0

# Compute the inverse hyperbolic sine of the value
result = np.arcsinh(value)

# Print the result
print("arcsinh(1.0):", result)

Output:

arcsinh(1.0): 0.881373587019543

2. Computing arcsinh for an Array of Values

We compute the inverse hyperbolic sine for an array of values.

</>
Copy
import numpy as np

# Define an array of values
values = np.array([-2, -1, 0, 1, 2])

# Compute the inverse hyperbolic sine for each value
arcsinh_values = np.arcsinh(values)

# Print the results
print("Input values:", values)
print("arcsinh values:", arcsinh_values)

Output:

Input values: [-2 -1  0  1  2]
arcsinh values: [-1.44363548 -0.88137359  0.          0.88137359  1.44363548]

3. Using the out Parameter

Using an output array to store results instead of creating a new array.

</>
Copy
import numpy as np

# Define an array of values
values = np.array([-1, 0, 1])

# Create an output array with the same shape
output_array = np.ndarray(values.shape)

# Compute inverse hyperbolic sine and store the result in output_array
np.arcsinh(values, out=output_array)

# Print the results
print("Computed arcsinh values:", output_array)

Output:

Computed arcsinh values: [-0.88137359  0.          0.88137359]

4. Using the where Parameter

Using a condition to compute the inverse hyperbolic sine only for selected elements.

</>
Copy
import numpy as np

# Define an array of values
values = np.array([-2, -1, 0, 1, 2])

# Define a mask (compute arcsinh only where mask is True)
mask = np.array([True, False, True, False, True])

# Compute inverse hyperbolic sine where mask is True
result = np.arcsinh(values, where=mask)

# Print the results
print("Computed arcsinh values with mask:", result)

Output:

Computed arcsinh values with mask: [-1.44363548e+000  0.00000000e+000  0.00000000e+000  4.95242130e+223
  1.44363548e+000]

The arcsinh values are computed only for elements where mask=True. The other values remain unchanged.