math – Inverse Cosine in Python

math – Inverse Cosine in Python

We have the acos function, which returns the angle in radians.

>>> import math
>>> math.acos(0)
1.5707963267948966
>>> _ * 2 - math.pi
0.0

To augment the correct answers to use math.acos, it is also worth knowing that there are math functions suitable for complex numbers in cmath:

>>> import cmath
>>> cmath.acos(1j)
(1.5707963267948966-0.88137358701954294j)

Stick with math.acos if youre only interested in real numbers,

math – Inverse Cosine in Python

The result of math.acos() is in radians. So you need to convert that to degrees.

Here is how you can do:

import math
res = math.degrees (math.acos (value))

Leave a Reply

Your email address will not be published. Required fields are marked *