The numpy.acosh() function is same as that of numpy.arccosh() function.
NumPy acosh()
The numpy.acosh()
function computes the inverse hyperbolic cosine (acosh
) of each element in an input array.
The function requires input values to be greater than or equal to 1, as acosh(x)
is only defined for x ≥ 1
.
Syntax
numpy.acosh(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 acosh 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.acosh(x)
# Print the result
print("acosh(2.0):", result)
Output:
acosh(2.0): 1.3169578969248166

2. Computing acosh 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
acosh_values = np.acosh(values)
# Print the results
print("Input values:", values)
print("acosh values:", acosh_values)
Output:
Input values: [1. 1.5 2. 3. 5. ]
acosh 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 acosh and store the result in output_array
np.acosh(values, out=output_array)
# Print the results
print("Computed acosh values:", output_array)
Output:
Computed acosh values: [0. 1.3169579 1.76274717 2.06343707]

4. Using the where
Parameter
Using a condition to compute acosh 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 acosh only where mask is True)
mask = np.array([False, True, True, False])
# Compute acosh values where mask is True
result = np.acosh(values, where=mask)
# Print the results
print("Computed acosh values with mask:", result)
Output:
Computed acosh 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.