What is the numpy.arccos() function in Python?

Overview

The numpy.arccos() function in Python is used to determine the inverse sine, element-wise, of a given array.

Syntax

numpy.arccos(x, /, out=None, *, where=True)

Parameter values

The numpy.arccos() function takes the following parameter values:

  • x: This represents the x-coordinates on a unit circle. In a case where there are arguments, the domain is given as [-1, 1] This is a required parameter value.
  • out: This represents a location where the result is stored. This is an optional parameter value.
  • where: This is the condition over which the input is broadcast. At a given location where this condition is True, the resulting array will be set to the ufunc result. Otherwise, the resulting array will retain its original value. This is an optional parameter value.
  • **kwargs: This represents the other keyword arguments.

Return type

The numpy.arccos() function returns the inverse cosine of each element in a given array in radians and in a closed interval [0, pi].

Code example

import numpy as np
# creating an array
x = np.array([[1, 0], [-1, -0.5]])
# taking the arccos element-wise
myarray = np.arccos(x)
print(myarray)

Code explanation

  • Line 1: We import the numpy module.
  • Line 4: We create an array x, using the array() method.
  • Line 7: We implement the np.arccos() function on the array. Then, we assign the result to a variable called myarray.
  • Line 9: We print the variable myarray to the console.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources