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

ParameterTypeDescription
xarray_likeAngle values in radians. Each element will have its sine computed.
outndarray, None, or tuple of ndarray and None, optionalOptional output array where the result is stored. If None, a new array is created.
wherearray_like, optionalBoolean mask specifying which elements to compute. Elements where where=False retain their original value.
castingstr, optionalDefines the casting behavior when computing the sine function.
orderstr, optionalMemory layout order of the output array.
dtypedata-type, optionalDefines the data type of the output array.
subokbool, optionalDetermines 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