NumPy arctan() Function:
Numpy inverse tangent: The arctan() function of the NumPy module is used to calculate the inverse tangent (arc tangent) value of a given value. The value returned will be in the range -π/2 to π/2.
Syntax:
numpy.arctan(x, out=None)
Parameters
x: This is required. It is an array (array-like) having elements for which the arc tanget value is calculated.
out: This is optional. It is the location where the result will be saved. It must have a shape that the inputs broadcast to if it is provided. If None or not given, a newly allocated array is returned.
Return Value:Β
The arc tangent/inverse tangent value of each element of x is returned.
NumPy arctan() Function in Python
Example1
Approach:
- Import numpy module using the import keyword.
- Pass some random list as an argument to the array() function to create an array.
- Store it in a variable.
- Print the above-given array.
- Convert the above-given array angles into radians using the pi/180 of numpy module.
- Store it in the same variable.
- Pass the above radian angles array to the tan() function of the numpy module to get the tangent values of the given array angles.
- Store it in another variable.
- Pass the above tangent values array to the arctan() function of the numpy module to get the arc tangent(inverse tangent) values of the given array.
- Store it in another variable.
- Print the given array’s angles tangent values.
- Print the given array’s angles inverse tangent values in radians.
- Print the given array’s angles inverse tangent values in degrees by passing the above inverse tangent values to the degrees() function.
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword import numpy as np # Pass some random list as an argument to the array() function to # create an array. # Store it in a variable. gvn_arry = np.array([30, 45, 120, 180]) # Convert the above given array angles into radians using the pi/180 of # numpy module. # Store it in the same variable. gvn_arry = gvn_arry*np.pi/180 # Pass the above radian angles array to the tan() function of the # numpy module to get the tangent values of the given array angles # Store it in another variable. tangent_arry = np.tan(gvn_arry) # Pass the above tangent values array to the arctan() function of the # numpy module to get the arc tangent values of the given array inversetan_arry = np.arctan(tangent_arry) # Print the given array's angles tangent values print("The given array's angles tangent values:") print(tangent_arry) print() # Print the given array's angles inverse tangent values in radians print("The given array's angles inverse tangent values in radians:") print(inversetan_arry) print() # Print the given array's angles inverse tangent values in degrees by # passing the above inverse tangent values to the degrees() function. print("The given array's angles inverse tangent values in degrees:") print(np.degrees(inversetan_arry))
Output:
The given array's angles tangent values: [ 5.77350269e-01 1.00000000e+00 -1.73205081e+00 -1.22464680e-16] The given array's angles inverse tangent values in radians: [ 5.23598776e-01 7.85398163e-01 -1.04719755e+00 -1.22464680e-16] The given array's angles inverse tangent values in degrees: [ 3.0000000e+01 4.5000000e+01 -6.0000000e+01 -7.0167093e-15]
Example2
Approach:
- Import numpy module using the import keyword.
- Give the array as static input and store it in a variable.
- Print the above-given array.
- Pass the above-given array as an argument to the arctan() function of the numpy module to get the arc tangent(inverse tangent) values of given array elements.
- Store it in another variable.
- Print the arc tangent(inverse tangent) values of given array elements.
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword import numpy as np # Give the array as static input and store it in a variable gvn_arry = [1, 0.5, -0.2] # Print the above given array. print("The above given array is:") print(gvn_arry) # Pass the above given array as an argument to the arctan() function of the # numpy module to get the arc tangent(inverse tangent) values of # given array elements # Store it in another variable. inversetan_arry = np.arctan(gvn_arry) # Print the arc tangent(inverse tangent) values of given array elements print("The inverse tangent values of given array elements:") print(inversetan_arry)
Output:
The above given array is: [1, 0.5, -0.2] The inverse tangent values of given array elements: [ 0.78539816 0.46364761 -0.19739556]