5.5. Trigonometry#
In addition to arithmetical operators, NumPy provides lots of essential functions and constants to perform trigonometrical operations:
np.pi: π
np.sin: Sinus
np.cos: Cosinus
np.tan: Tangent
np.arcsin: Arc-sinus
np.arccos: Arc-cosinus
np.arctan: Arc-tangent
np.arctan2: Arc-tangent in the full plane, contrarily to np.arctan that only returns values from -π/2 (-90°) to +π (+90°)
np.deg2rad: Convert degrees to radians
np.rad2deg: Convert radians to degrees
np.abs: Absolute value
np.sqrt: Square root
In all trigonometric functions, angles are in radians by default. You can either convert to/from degrees by multiplying or dividing by \(\pi/180\) manually, or use np.deg2rad and np.rad2deg.
import numpy as np
import matplotlib.pyplot as plt
angle = np.linspace(0, 2 * np.pi, 100)
plt.plot(angle, np.sin(angle));