numpy.arccos() in Python (original) (raw)
Last Updated : 08 Mar, 2024
numpy.arccos(x[, out]) = ufunc ‘arccos’) : This mathematical function helps user to calculate inverse cos for all x(being the array elements).
Parameters :
array : [array_like]elements are in radians. out : [array_like]array of same shape as x.
Note :
2pi Radians = 360 degrees
The convention is to return the angle z whose real part lies in [0, pi].
Return :
An array with inverse cosine of x for all x i.e. array elements.
The values are in the closed interval [-pi/2, pi/2].
Code #1 : Working
import
numpy as np
in_array
=
[
0
,
1
,
0.3
,
-
1
]
print
(
"Input array : \n"
, in_array)
arccos_Values
=
np.arccos(in_array)
print
(
"\nInverse Cosine values : \n"
, arccos_Values)
Output :
Input array : [0, 1, 0.3, -1]
Inverse Cosine values : [ 1.57079633 0. 1.26610367 3.14159265]
Code #2 : Graphical representation
import
numpy as np
import
matplotlib.pyplot as plt
in_array
=
np.linspace(
-
np.pi, np.pi,
12
)
out_array1
=
np.cos(in_array)
out_array2
=
np.arccos(in_array)
print
(
"in_array : "
, in_array)
print
(
"\nout_array with cos : "
, out_array1)
print
(
"\nout_arraywith arccos : "
, out_array1)
plt.plot(in_array, out_array1,
`` color
=
'blue'
, marker
=
"*"
)
plt.plot(in_array, out_array2,
`` color
=
'red'
, marker
=
"o"
)
plt.title(
"blue : numpy.cos() \nred : numpy.arccos()"
)
plt.xlabel(
"X"
)
plt.ylabel(
"Y"
)
plt.show()
Output :
in_array : [-3.14159265 -2.57039399 -1.99919533 -1.42799666 -0.856798 -0.28559933 0.28559933 0.856798 1.42799666 1.99919533 2.57039399 3.14159265]
out_array with cos : [-1. -0.84125353 -0.41541501 0.14231484 0.65486073 0.95949297 0.95949297 0.65486073 0.14231484 -0.41541501 -0.84125353 -1. ]
out_arraywith arccos : [-1. -0.84125353 -0.41541501 0.14231484 0.65486073 0.95949297 0.95949297 0.65486073 0.14231484 -0.41541501 -0.84125353 -1. ] RuntimeWarning: invalid value encountered in arccos out_array1 = np.sin(in_array)
Similar Reads
- numpy.arccosh() in Python numpy.arccosh() : This mathematical function helps user to calculate inverse hyperbolic cosine, element-wise for all arr. Syntax : numpy.arccosh(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, ufunc 'arccosh') Parameters : arr : array_like Input array. out : [ndarray, op 2 min read
- numpy.cos() in Python numpy.cos(x[, out]) = ufunc 'cos') : This mathematical function helps user to calculate trigonometric cosine for all x(being the array elements). Parameters : array : [array_like]elements are in radians. 2pi Radians = 360 degrees Return : An array with trigonometric cosine of x for all x i.e. array 2 min read
- numpy.arcsin() in Python numpy.arcsin(x[, out]) = ufunc 'arcsin') : This mathematical function helps user to calculate inverse sine for all x(being the array elements). Parameters : array : [array_like]elements are in radians. out : [array_like]array of same shape as x. Return : An array with inverse sine of x for all x i.e 2 min read
- numpy.cosh() in Python The numpy.cosh() is a mathematical function that helps user to calculate hyperbolic cosine for all x(being the array elements). Equivalent to 1/2 * (np.exp(x) - np.exp(-x)) and np.cos(1j*x). Syntax : numpy.cosh(x[, out]) = ufunc 'cos') Parameters : array : [array_like] elements are in radians. 2pi R 2 min read
- numpy.arcsinh() in Python numpy.arcsinh() : This mathematical function helps user to calculate inverse hyperbolic sine, element-wise for all arr. Syntax : numpy.arcsinh(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, ufunc 'arcsinh') Parameters : arr : array_like Input array. out : [ndarray, opti 2 min read
- numpy.arctan() in Python numpy.arctan(x[, out]) = ufunc 'arctan') : This mathematical function helps user to calculate inverse tangent for all x(being the array elements). Parameters : array : [array_like]elements are in radians. out : [array_like]array of same shape as x. Note : 2pi Radians = 360 degrees The convention is 2 min read
- numpy.arctan2() in Python The numpy.arctan2() method computes element-wise arc tangent of arr1/arr2 choosing the quadrant correctly. The quadrant is chosen so that arctan2(x1, x2) is the signed angle in radians between the ray ending at the origin and passing through the point (1, 0), and the ray ending at the origin and pas 2 min read
- numpy.arctanh in Python() numpy.arctanh() : This mathematical function helps user to calculate inverse hyperbolic tangent, element-wise for all arr. Syntax : numpy.arctanh(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, ufunc 'arctanh') Parameters : arr : array_like Input array. out : [ndarray, o 2 min read
- NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read
- numpy.arange() in Python numpy.arange() function creates an array of evenly spaced values within a given interval. It is similar to Python's built-in range() function but returns a NumPy array instead of a list. Let's understand with a simple example: [GFGTABS] Python import numpy as np #create an array arr= np.arange(5 , 1 2 min read