NumPy sin()
The numpy.sin() function computes the trigonometric sine of each element in an input array.
The input values should be in radians.
Syntax
</>
Copy
numpy.sin(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)
Parameters
| Parameter | Type | Description |
|---|---|---|
x | array_like | Angle values in radians. Each element will have its sine computed. |
out | ndarray, None, or tuple of ndarray and None, optional | Optional output array where the result is stored. If None, a new array is created. |
where | array_like, optional | Boolean mask specifying which elements to compute. Elements where where=False retain their original value. |
casting | str, optional | Defines the casting behavior when computing the sine function. |
order | str, optional | Memory layout order of the output array. |
dtype | data-type, optional | Defines the data type of the output array. |
subok | bool, optional | Determines if subclasses of ndarray are preserved in the output. |
Return Value
Returns an array with the sine values of the input array elements. If the input is a scalar, a scalar is returned.
Examples
1. Computing Sine of a Single Value
Here, we compute the sine of a single angle in radians.
</>
Copy
import numpy as np
# Define an angle in radians
angle = np.pi / 2 # 90 degrees in radians
# Compute the sine of the angle
result = np.sin(angle)
# Print the result
print("Sine of 90 degrees (π/2 radians):", result)
Output:
Sine of 90 degrees (π/2 radians): 1.0
