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 radians -
np.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].
