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

FunctionDescriptionExample
np.sin(x)Sinenp.sin(np.pi/2) = 1
np.cos(x)Cosinenp.cos(np.pi) = -1
np.tan(x)Tangentnp.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

FunctionDescription
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

  1. Create an array [0, 30, 45, 60, 90] in degrees and compute sin, cos, tan.

  2. Compute inverse sine and inverse cosine of [0, 0.5, 1].

  3. Convert [0, π/6, π/4, π/2] from radians to degrees.

  4. Compute hyperbolic sine, cosine, tangent for [0,1,2].

You may also like...