NumPy Trigonometric Functions
🌐 NumPy Trigonometric Functions
NumPy provides vectorized trigonometric functions that operate element-wise on arrays. These functions are faster than Python’s built-in math module and support radians by default.
1. Basic Trigonometric Functions
| Function | Description | Example |
|---|---|---|
np.sin(x) | Sine | np.sin(np.pi/2) = 1 |
np.cos(x) | Cosine | np.cos(np.pi) = -1 |
np.tan(x) | Tangent | np.tan(np.pi/4) = 1 |
np.arcsin(x) | Inverse sine (radians) | np.arcsin(1) = π/2 |
np.arccos(x) | Inverse cosine (radians) | np.arccos(0) = π/2 |
np.arctan(x) | Inverse tangent (radians) | np.arctan(1) = π/4 |
2. Example: Sine, Cosine, Tangent
Note: Tangent is undefined at π/2 → returns
inf
3. Inverse Trigonometric Functions
Returns radians by default
4. Degree-Radian Conversion
np.deg2rad()→ convert degrees to radiansnp.rad2deg()→ convert radians to degrees
5. Hyperbolic Trigonometric Functions
| Function | Description |
|---|---|
np.sinh(x) | Hyperbolic sine |
np.cosh(x) | Hyperbolic cosine |
np.tanh(x) | Hyperbolic tangent |
np.arcsinh(x) | Inverse hyperbolic sine |
np.arccosh(x) | Inverse hyperbolic cosine |
np.arctanh(x) | Inverse hyperbolic tangent |
6. Notes & Tips
Trigonometric functions use radians, not degrees
Use vectorized operations on arrays → faster than Python loops
Be careful with domain limits for inverse trig functions
🎯 Practice Exercises
Create an array
[0, 30, 45, 60, 90]in degrees and compute sin, cos, tan.Compute inverse sine and inverse cosine of
[0, 0.5, 1].Convert
[0, π/6, π/4, π/2]from radians to degrees.Compute hyperbolic sine, cosine, tangent for
[0,1,2].
