# Compute the inverse cosine with scimath in Python

PythonNumpyServer Side ProgrammingProgramming

To compute the inverse cosine with scimath, use the numpy.emath.arccos() method in Python. Return the “principal value” of the inverse cosine of x. For real x such that abs(x) <= 1, this is a real number in the closed interval [0,π]. Otherwise, the complex principle value is returned.

The method returns the inverse cosine(s) of the x value(s). If x was a scalar, so is out, otherwise an array object is returned. The 1st parameter is the value(s) whose arccos is (are) required.

## Steps

At first, import the required libraries −

import numpy as np

Create a numpy array using the array() method −

arr = np.array([1, -1, 2, 0])


Display the array −

print("Array...\n", arr)

Get the type of the array −

print("\nOur Array type...\n", arr.dtype)


Get the dimensions of the Array −

print("\nOur Array Dimension...\n",arr.ndim)

To compute the inverse cosine with scimath, use the numpy.emath.arccos() method in Python −

print("\nResult...",np.emath.arccos(arr))


## Example

import numpy as np

# Create a numpy array using the array() method
arr = np.array([1, -1, 2, 0])

# Display the array
print("Array...\n", arr)

# Get the type of the array
print("\nOur Array type...\n", arr.dtype)

# Get the dimensions of the Array
print("\nOur Array Dimensions...\n",arr.ndim)

# Get the number of elements in the Array
print("\nNumber of elements...\n", arr.size)

# To compute the inverse cosine with scimath, use the numpy.emath.arccos() method in Python
print("\nResult...",np.emath.arccos(arr))

## Output

Array...
[ 1 -1 2 0]

Our Array type...
int64

Our Array Dimensions...
1

Number of elements...
4

Result... [0. -0.j 3.14159265-0.j 0. -1.3169579j
1.57079633-0.j ]