numpy.arctan() in Python (original) (raw)
Last Updated : 07 Mar, 2024
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 to return the angle z whose real part lies in [-pi/2, pi/2].
Return :
An array with inverse tangent 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)
arctan_Values
=
np.arctan(in_array)
print
(
"\nInverse Tangent values : \n"
,
`` arctan_Values)
Output :
Input array : [0, 1, 0.3, -1]
Inverse Tangent values : [ 0. 0.78539816 0.29145679 -0.78539816]
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.tan(in_array)
out_array2
=
np.arctan(in_array)
print
(
"in_array : "
, in_array)
print
(
"\nout_array with tan : "
, out_array1)
print
(
"\nout_arraywith arctan : "
, 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.tan() \nred : numpy.arctan()"
)
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 tan : [ 1.22464680e-16 6.42660977e-01 2.18969456e+00 -6.95515277e+00 -1.15406152e+00 -2.93626493e-01 2.93626493e-01 1.15406152e+00 6.95515277e+00 -2.18969456e+00 -6.42660977e-01 -1.22464680e-16]
out_arraywith arctan : [ 1.22464680e-16 6.42660977e-01 2.18969456e+00 -6.95515277e+00 -1.15406152e+00 -2.93626493e-01 2.93626493e-01 1.15406152e+00 6.95515277e+00 -2.18969456e+00 -6.42660977e-01 -1.22464680e-16]
Similar Reads
- 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.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.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 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.arccos() in Python 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 r 2 min read
- numpy.alen() in Python numpy.alen() function is used to return the length of the first dimension of the input array. Syntax : numpy.alen(arr) Parameters : arr : [array_like] Input array. Return : [int]Length of the first dimension of arr. Code #1 : # Python program explaining # alen() function import numpy as geek # input 1 min read
- 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.angle() in Python numpy.angle() function is used when we want to compute the angle of the complex argument. A complex number is represented by “ x + yi " where x and y are real number and i= (-1)^1/2. The angle is calculated by the formula tan-1(x/y). Syntax : numpy.angle(z, deg=0) Parameters : z : [array_like] A com 2 min read
- numpy.asarray() in Python numpy.asarray()function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of lists and arrays. Syntax : numpy.asarray(arr, dtype=None, order=None) Parameters : arr : [array_like] Input data, in any form that can be converted to a 2 min read