ufunc Trigonometric
NumPy provides a variety of trigonometric ufuncs for operations on angles. These include sine, cosine, tangent, and their inverses, which are commonly used in engineering, physics, and mathematics.
Key Topics
Basic Trigonometric Functions
NumPy's trigonometric functions include sin
, cos
, and tan
, which operate on angles in radians.
Example
# Trigonometric functions
import numpy as np
angles = np.array([0, np.pi/2, np.pi])
sine = np.sin(angles)
cosine = np.cos(angles)
tangent = np.tan(angles)
print("Sine:", sine)
print("Cosine:", cosine)
print("Tangent:", tangent)
Output
Sine: [0. 1. 0.]
Cosine: [ 1. 0. -1.]
Tangent: [ 0. inf -0.]
Cosine: [ 1. 0. -1.]
Tangent: [ 0. inf -0.]
Explanation: Trigonometric ufuncs compute the sine, cosine, and tangent of angles in radians. Note that tangent of π/2
results in infinity due to division by zero.
Inverse Trigonometric Functions
Inverse trigonometric ufuncs include arcsin
, arccos
, and arctan
, which compute angles in radians from trigonometric ratios.
Example
# Inverse trigonometric functions
ratios = np.array([0, 1, -1])
arcsine = np.arcsin(ratios)
arccosine = np.arccos(ratios)
arctangent = np.arctan(ratios)
print("Arcsine:", arcsine)
print("Arccosine:", arccosine)
print("Arctangent:", arctangent)
Output
Arcsine: [ 0. 1.57 -1.57]
Arccosine: [1.57 0. 3.14]
Arctangent: [ 0. 0.78 -0.78]
Arccosine: [1.57 0. 3.14]
Arctangent: [ 0. 0.78 -0.78]
Explanation: Inverse trigonometric ufuncs compute angles in radians from trigonometric ratios, useful for angle determination.
Key Takeaways
- Basic Functions: Use
sin
,cos
, andtan
for trigonometric computations on angles. - Inverse Functions: Use
arcsin
,arccos
, andarctan
to compute angles from ratios. - Applications: Widely used in geometry, physics, and signal processing.