English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
NumPy bietet Standardtrigonometrische Funktionen: sin(), cos(), tan().
import numpy as np a = np.array([0,30,45,60,90]) print ('Sinuswerte verschiedener Winkel: ') # Durch Multiplikation mit pi/180 in Bogenmaß umwandeln print (np.sin(a*np.pi/180)) print ('\n') print ('Kosinuswerte der Winkel im Array: ') print (np.cos(a*np.pi/180)) print ('\n') print ('Tangenswerte der Winkel im Array: ') print (np.tan(a*np.pi/180))
输出结果为:
Sinuswerte verschiedener Winkel: [0. 0.5 0.70710678 0.8660254 1. ] Kosinuswerte der Winkel im Array: [1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01 6.12323400e-17] Tangenswerte der Winkel im Array: [0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00 1.63312394e+16]
Arcsin, arccos und arctan geben die Umkehrfunktionen von Sinus, Kosinus und Tangens des gegebenen Winkels zurück.
Die Ergebnisse dieser Funktionen können durch die Funktion numpy.degrees() in Grad umgewandelt werden.
import numpy as np a = np.array([0,30,45,60,90]) print ('Array mit Sinuswerten: ') sin = np.sin(a*np.pi/180) print (sin) print ('\n') print ('Berechnung des Arcus tangens des Winkels, Rückgabewert in Bogenmaß: ') inv = np.arcsin(sin) print (inv) print ('\n') print ('Durch Umwandlung in das Grad-System überprüfen: ') print (np.degrees(inv)) print ('\n') print ('Arcus cosinus und Arcus tangens verhalten sich ähnlich: ') cos = np.cos(a*np.pi/180) print (cos) print ('\n') print ('Arcus cosinus: ') inv = np.arccos(cos) print (inv) print ('\n') print ('Grad-System: ') print (np.degrees(inv)) print ('\n') print ('tan Funktion: ') tan = np.tan(a*np.pi/180) print (tan) print ('\n') print ('Arcus tangens: ') inv = np.arctan(tan) print (inv) print ('\n') print ('Grad-System: ') print (np.degrees(inv))
输出结果为:
Array mit Sinuswerten: [0. 0.5 0.70710678 0.8660254 1. ] Berechnung des Arcus tangens des Winkels, Rückgabewert in Bogenmaß: [0. 0.52359878 0.78539816 1.04719755 1.57079633] Durch Umwandlung in das Grad-System überprüfen: [ 0. 30. 45. 60. 90.] Arcus cosinus und Arcus tangens verhalten sich ähnlich: [1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01 6.12323400e-17] Arcus cosinus: [0. 0.52359878 0.78539816 1.04719755 1.57079633] Grad-System: [ 0. 30. 45. 60. 90.] tan Funktion: [0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00 1.63312394e+16] Arcus tangens: [0. 0.52359878 0.78539816 1.04719755 1.57079633] Grad-System: [ 0. 30. 45. 60. 90.]
numpy.around() 函数返回指定数字的四舍五入值。
numpy.around(a,decimals)
参数说明:
a: 数组 decimals: 舍入的小数位数。 默认值为0。 如果为负,整数将四舍五入到小数点左侧的位置
import numpy as np a = np.array([1.0,5.55, 123, 0.567, 25.532]) print ('原数组:') print (a) print ('\n') print ('舍入后:') print (np.around(a)) print (np.around(a, decimals = 1)) print (np.around(a, decimals = -1))
输出结果为:
原数组: [ 1. 5.55 123. 0.567 25.532] 舍入后: [ 1. 6. 123. 1. 26.] [ 1. 5.6 123. 0.6 25.5] [ 0. 10. 120. 0. 30.]
numpy.floor() 返回小于或者等于指定表达式的最大整数,即向下取整。
import numpy as np a = np.array([-1.7, 1.5, -0.2, 0.6, 10]) print ('提供的数组:') print (a) print ('\n') print ('修改后的数组:') print (np.floor(a))
输出结果为:
提供的数组: [-1.7 1.5 -0.2 0.6 10. ] 修改后的数组: [-2. 1. -1. 0. 10.]
numpy.ceil() 返回大于或者等于指定表达式的最小整数,即向上取整。
import numpy as np a = np.array([-1.7, 1.5, -0.2, 0.6, 10]) print ('提供的数组:') print (a) print ('\n') print ('修改后的数组:') print (np.ceil(a))
提供的数组: [-1.7 1.5 -0.2 0.6 10. ] 修改后的数组: [-1. 2. -0. 1. 10.]