【转】numpy 三角函数 sin()、cos()、tan() 反三角函数arcsin,arccos,arctan numpy.degrees()
三角函数
1 import numpy as np 2 3 a = np.array([0,30,45,60,90]) 4 print (\'不同角度的正弦值:\') 5 # 通过乘 pi/180 转化为弧度 6 print (np.sin(a*np.pi/180)) 7 print (\'\n\') 8 print (\'数组中角度的余弦值:\') 9 print (np.cos(a*np.pi/180)) 10 print (\'\n\') 11 print (\'数组中角度的正切值:\') 12 print (np.tan(a*np.pi/180))
结果:
1 不同角度的正弦值: 2 [0. 0.5 0.70710678 0.8660254 1. ] 3 4 5 数组中角度的余弦值: 6 [1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01 7 6.12323400e-17] 8 9 10 数组中角度的正切值: 11 [0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00 12 1.63312394e+16]
反三角函数
1 import numpy as np 2 3 a = np.array([0,30,45,60,90]) 4 print (\'含有正弦值的数组:\') 5 sin = np.sin(a*np.pi/180) 6 print (sin) 7 print (\'\n\') 8 print (\'计算角度的反正弦,返回值以弧度为单位:\') 9 inv = np.arcsin(sin) 10 print (inv) 11 print (\'\n\') 12 print (\'通过转化为角度制来检查结果:\') 13 print (np.degrees(inv)) 14 print (\'\n\') 15 print (\'arccos 和 arctan 函数行为类似:\') 16 cos = np.cos(a*np.pi/180) 17 print (cos) 18 print (\'\n\') 19 print (\'反余弦:\') 20 inv = np.arccos(cos) 21 print (inv) 22 print (\'\n\') 23 print (\'角度制单位:\') 24 print (np.degrees(inv)) 25 print (\'\n\') 26 print (\'tan 函数:\') 27 tan = np.tan(a*np.pi/180) 28 print (tan) 29 print (\'\n\') 30 print (\'反正切:\') 31 inv = np.arctan(tan) 32 print (inv) 33 print (\'\n\') 34 print (\'角度制单位:\') 35 print (np.degrees(inv))
结果:
1 含有正弦值的数组: 2 [0. 0.5 0.70710678 0.8660254 1. ] 3 4 5 计算角度的反正弦,返回值以弧度为单位: 6 [0. 0.52359878 0.78539816 1.04719755 1.57079633] 7 8 9 通过转化为角度制来检查结果: 10 [ 0. 30. 45. 60. 90.] 11 12 13 arccos 和 arctan 函数行为类似: 14 [1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01 15 6.12323400e-17] 16 17 18 反余弦: 19 [0. 0.52359878 0.78539816 1.04719755 1.57079633] 20 21 22 角度制单位: 23 [ 0. 30. 45. 60. 90.] 24 25 26 tan 函数: 27 [0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00 28 1.63312394e+16] 29 30 31 反正切: 32 [0. 0.52359878 0.78539816 1.04719755 1.57079633] 33 34 35 角度制单位: 36 [ 0. 30. 45. 60. 90.]
转自: