NumPy arccosh()
The numpy.arccosh()
function computes the inverse hyperbolic cosine (arccosh
) of each element in an input array.
The function requires input values to be greater than or equal to 1, as arccosh(x)
is only defined for x ≥ 1
.
Syntax
numpy.arccosh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)
Parameters
Parameter | Type | Description |
---|---|---|
x | array_like | Input values. Must be greater than or equal to 1. |
out | ndarray, None, or tuple of ndarray and None, optional | Optional output array to store the result. If None, a new array is created. |
where | array_like, optional | Boolean mask specifying which elements to compute. Elements where where=False retain their original value. |
casting | str, optional | Defines the casting behavior when computing the function. |
order | str, optional | Memory layout order of the output array. |
dtype | data-type, optional | Defines the data type of the output array. |
subok | bool, optional | Determines if subclasses of ndarray are preserved in the output. |
Return Value
Returns an array with the inverse hyperbolic cosine values of the input elements. If the input is a scalar, a scalar is returned.
Examples
1. Computing arccosh of a Single Value
Here, we compute the inverse hyperbolic cosine of a single value.
import numpy as np
# Define a value greater than or equal to 1
x = 2.0
# Compute the inverse hyperbolic cosine
result = np.arccosh(x)
# Print the result
print("arccosh(2.0):", result)
Output:
arccosh(2.0): 1.3169578969248166

2. Computing arccosh for an Array of Values
We compute the inverse hyperbolic cosine for multiple values provided in an array.
import numpy as np
# Define an array of values (must be ≥ 1)
values = np.array([1, 1.5, 2, 3, 5])
# Compute the inverse hyperbolic cosine for each value
arccosh_values = np.arccosh(values)
# Print the results
print("Input values:", values)
print("arccosh values:", arccosh_values)
Output:
Input values: [1. 1.5 2. 3. 5. ]
arccosh values: [0. 0.96242365 1.3169579 1.76274717 2.29243167]

3. Using the out
Parameter
Using an output array to store results instead of creating a new array.
import numpy as np
# Define an array of values (must be ≥ 1)
values = np.array([1, 2, 3, 4])
# Create an output array with the same shape
output_array = np.ndarray(shape=values.shape)
# Compute arccosh and store the result in output_array
np.arccosh(values, out=output_array)
# Print the results
print("Computed arccosh values:", output_array)
Output:
Computed arccosh values: [0. 1.3169579 1.76274717 2.06343707]

4. Using the where
Parameter
Using a condition to compute arccosh only for selected elements.
import numpy as np
# Define an array of values (must be ≥ 1)
values = np.array([1, 2, 3, 4])
# Define a mask (compute arccosh only where mask is True)
mask = np.array([False, True, True, False])
# Compute arccosh values where mask is True
result = np.arccosh(values, where=mask)
# Print the results
print("Computed arccosh values with mask:", result)
Output:
Computed arccosh values with mask: [0. 1.3169579 1.76274717 0. ]

The inverse hyperbolic cosine values are computed only for elements where mask=True
. The other values remain unchanged.