NumPy Arccosh – A Complete Guide

Hello Readers! Welcome to another tutorial on NumPy Mathematical Functions. In this tutorial, we will understand the NumPy arccosh function along with practicing a lot of examples. We will also plot the graph using Matplotlib Library.

Without any further due, let’s get started.

Also read: NumPy Arcsinh – A Complete Guide

What is hyperbolic arc cos (inverse cos)- A Quick Overview

• arccosh is the inverse hyperbolic cosine function.
• The equivalent expression of the arccosh is:
• The domain of the arccosh function is [1, infinity). Here, infinity is not included.
• The range of the arccosh function is [1, infinity).

Also read: NumPy Interview Questions: Prepare Yourself For Your Python Job Interview

What is NumPy Arccosh?

The NumPy Arccosh function is also one of the inverse hyperbolic trigonometric functions provided by the NumPy library. Using this function, we can calculate the inverse hyperbolic cosine values of the input passed to the arccosh function.

The numpy arccosh function can be accessed as `numpy.arccosh()`.

Syntax: numpy.arccosh(input) where the input can be a single number, a complex number as well as a NumPy array of numbers.

Working with NumPy Arccosh

Let’s try out some examples.

Using numpy.arccosh() with NumPy array having numbers

```import numpy as np

a = np.array(( 2 , 3 , 10 , 90 , 100))

b = np.arccosh(a)

print("Input Values:\n",a)

print("Arccosh values:\n",b)
```

Output

```Input Values:
[  2   3  10  90 100]
Arccosh values:
[1.3169579  1.76274717 2.99322285 5.19292599 5.29829237]
```

Let’s pass some pi values as an argument to the arccosh function and observe the outputs 🙂

Using numpy.arccosh() function with NumPy array having angles in radians

```import numpy as np

a = np.array((np.pi/2 , 3*np.pi/2 , np.pi))

b = np.arccosh(a)

print("Input Array:\n",a)

print("Arccosh Values:\n",b)
```

Output

```Input Array:
[1.57079633 4.71238898 3.14159265]
Arccosh Values:
[1.02322748 2.23188925 1.81152627]
```

Here, we cannot pass a value lower than 1 as it will be out of the domain of the arccosh function which will give nan as an output.

Task: Try passing 1 as an argument to the arccosh function and observe the output.

Working with Complex Numbers

```import numpy as np

print("Arccosh of 2+3j is :\n",np.arccosh(2+3j))

print("Arccosh of 1+5j is :\n",np.arccosh(1+5j))

print("Arccosh of 0.5+0.5j is :\n",np.arccosh(0.5+0.5j))

print("Arccosh of -1-1j is :\n",np.arccosh(-1-1j))

```

Output

```Arccosh of 2+3j is :
(1.9833870299165355+1.0001435424737972j)
Arccosh of 1+5j is :
(2.3309746530493123+1.3770031902399644j)
Arccosh of 0.5+0.5j is :
(0.5306375309525179+1.118517879643706j)
Arccosh of -1-1j is :
(1.0612750619050357-2.2370357592874117j)
```

Working with Invalid Numbers

Here, we will pass some invalid inputs to the arccosh function and observe the outputs.

```import numpy as np

print("The arccosh of 0 is:",np.arccosh(0))

print("The arccosh of -1 is:",np.arccosh(-1))

print("The arccosh of 0.5 is:",np.arccosh(0.5))
```

Output

In all the above cases, the output will be `nan`.

That was all about passing different arguments to the arccosh function. Now, let’s plot the curve of the arccosh function using the Matplotlib Library.

Visualizing the Arccosh function

```import numpy as np

import matplotlib.pyplot as plt

a = np.linspace(1 , 20 , 50)

b = np.arccosh(a)

plt.plot(a , b , color = "blue" , marker = "o")

plt.title("numpy.arccosh()")

plt.xlabel("X")

plt.ylabel("Y")

plt.show()
```

Output

So, that was all about the arccosh function. This function is pretty simple to use. Keep exploring awesome posts on various python topics here.