np.sin(), along with np.cos() and np.tan(), expects its input in radians, not degrees — a common source of bugs for people used to degree-based trigonometry elsewhere. To convert degrees to radians before calling it, use np.radians(), and np.degrees() to convert a result back if needed. Sine is periodic and bounded between -1 and 1 for any real input, which makes it a common building block for generating smooth, repeating waveforms.
1Understanding np.sin()
np.sin(), along with np.cos() and np.tan(), expects its input in radians, not degrees — a common source of bugs for people used to degree-based trigonometry elsewhere. To convert degrees to radians before calling it, use np.radians(), and np.degrees() to convert a result back if needed. Sine is periodic and bounded between -1 and 1 for any real input, which makes it a common building block for generating smooth, repeating waveforms.
Always convert degrees to radians with np.radians() before passing angle values to np.sin()/np.cos()/np.tan() — passing raw degree values directly is one of the most common trigonometry bugs in NumPy code.
import numpy as np
angles = np.array([0, np.pi / 2, np.pi])
print(np.sin(angles))2Practical Example
Here is a real-world application of np.sin() showing how it is used in production NumPy code.
import numpy as np
degrees = np.array([0, 90, 180])
radians = np.radians(degrees)
print(np.sin(radians))3Best Practices
Follow these guidelines when working with np.sin():
1. Convert degree values to radians with np.radians() before calling any trigonometric function, since they all expect radians
2. Use np.linspace() to generate an evenly-spaced set of angle inputs when plotting a smooth sine curve
3. Remember floating-point precision means sin(pi) evaluates to a tiny non-zero number rather than exactly 0 — use np.isclose() rather than == when checking trigonometric results against expected exact values
Tip: Always convert degrees to radians with np.radians() before passing angle values to np.sin()/np.cos()/np.tan() — passing raw degree values directly is one of the most common trigonometry bugs in NumPy code.
import numpy as np
angles = np.array([0, np.pi / 2, np.pi])
print(np.sin(angles))