numpy三角関数sin()、cos()、tan()逆三角関数arcsin、arccos、arctan numpy.degrees()



Numpy Trigonometric Functions Sin



三角関数

import numpy as np a = np.array([0,30,45,60,90]) print ('Sine value of different angles:') # Convert to radians by multiplying pi/180 print (np.sin(a*np.pi/180)) print (' ') print ('Cosine of angles in the array:') print (np.cos(a*np.pi/180)) print (' ') print ('Tangent of angle in array:') print (np.tan(a*np.pi/180))

結果:

Sine values ​​at different angles: [0. 0.5 0.70710678 0.8660254 1. ] The cosine of the angle in the array: [1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01 6.12323400e-17] The tangent of the angle in the array: [0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00 1.63312394e+16]

逆三角関数

import numpy as np a = np.array([0,30,45,60,90]) print ('Array containing sine values:') sin = np.sin(a*np.pi/180) print (sin) print (' ') print ('Calculate the arc sine of the angle, the return value is in radians:') inv = np.arcsin(sin) print (inv) print (' ') print ('Check the result by converting to an angle system:') print (np.degrees(inv)) print (' ') print ('arccos and arctan functions behave similarly:') cos = np.cos(a*np.pi/180) print (cos) print (' ') print ('Inverse cosine:') inv = np.arccos(cos) print (inv) print (' ') print ('Angle unit:') print (np.degrees(inv)) print (' ') print ('tan function:') tan = np.tan(a*np.pi/180) print (tan) print (' ') print ('Anyway:') inv = np.arctan(tan) print (inv) print (' ') print ('Angle unit:') print (np.degrees(inv))

結果:



Array with sine values: [0. 0.5 0.70710678 0.8660254 1. ] Calculate the arc sine of the angle, the return value is in radians: [0. 0.52359878 0.78539816 1.04719755 1.57079633] Check the results by converting to an angle system: [ 0. 30. 45. 60. 90.] The arccos and arctan functions behave similarly: [1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01 6.12323400e-17] Inverse cosine: [0. 0.52359878 0.78539816 1.04719755 1.57079633] Angle system unit: [ 0. 30. 45. 60. 90.] tan function: [0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00 1.63312394e+16] Arctangent: [0. 0.52359878 0.78539816 1.04719755 1.57079633] Angle system unit: [ 0. 30. 45. 60. 90.]

参考記事:ルーキーチュートリアル-NumPy数学関数-三角関数