Facebook Page Twitter Page LinkedIn Page
× NumPy Tutorial NumPy Resources


The NumPy arccos() function is used to calculate arc cosine (inverse cosine) of given value. The return value will be in the range 0 through 𝜋.

Syntax

numpy.arccos(x, out=None)

Parameters

x Required. Specify array (array_like) containing elements in range [-1, 1], of which the arc cosine is calculated.
out Optional. Specify a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.

Return Value

Returns the inverse cosine of each element in x.

Example:

In the below example, numpy arccos() function is used to calculate the inverse cosine of each element present in array cosArr.

import numpy as np

Arr = np.array([0, 30, 60, 90])
#converting the angles in radians
Arr = Arr*np.pi/180

cosArr = np.cos(Arr)
inv_cosArr = np.arccos(cosArr)
print("The cos value of angles:")
print(cosArr)
print("The inverse of the cos value (in radians):")
print(inv_cosArr)
print("The inverse of the cos value (in degrees):")
print(np.degrees(inv_cosArr))

The output of the above code will be:

The cos value of angles:
[  1.00000000e+00   8.66025404e-01   5.00000000e-01   6.12323400e-17]
The inverse of the cos value (in radians):
[ 0.          0.52359878  1.04719755  1.57079633]
The inverse of the cos value (in degrees):
[  0.  30.  60.  90.]

❮ NumPy - Functions