Python Math atan() Method
atan() Returns the value of the arctangent radian of x.
Python Math atan() Syntax
Here is the syntax of the atan() method:
import math
math.atan(x)
Note: atan() is not directly accessible, you need to import the math module and then call the method via the math static object.
Python Math atan() Parameters
- x : A value.
Python Math atan() Return Value
Returns the value of the arctangent radian of x.
Python Math atan() Example#1
The following shows an example of using the atan() method.
#!/usr/bin/python3
import math
print ("atan(0.128) : ", math.atan(0.128))
print ("atan(0) : ", math.atan(0))
print ("atan(10) : ", math.atan(10))
print ("atan(-1) : ", math.atan(-1))
print ("atan(1) : ", math.atan(1))
Output:
Python Math atan() Example#2
#!/usr/bin/python3
import math
import numpy as np
import matplotlib.pyplot as plt
in_array = np.linspace(0, np.pi, 10)
out_array = []
for i in range(len(in_array)):
out_array.append(math.atan(in_array[i]))
i += 1
print("Input_Array : \n", in_array)
print("\nOutput_Array : \n", out_array)
plt.plot(in_array, out_array, "go:")
plt.title("math.atan() in apidemos.com")
plt.xlabel("X")
plt.ylabel("Y")
plt.show()
Output:
deepinout@ubuntu:~/apidemos.com$ python3 demos.py
Input_Array :
[0. 0.34906585 0.6981317 1.04719755 1.3962634 1.74532925
2.0943951 2.44346095 2.7925268 3.14159265]
Output_Array :
[0.0, 0.3358423725664079, 0.6094709714274295, 0.808448792630022, 0.9492822422213403, 1.0504981725497873, 1.1253388328842984, 1.1823365638628716, 1.2269249964859286, 1.2626272556789118]