Trigonometric evaluation
Compute sine values for one angle or many angles.
NumPy · Function
Computes the trigonometric sine element-wise for angles expressed in radians. It accepts scalar or array-like input and supports standard ufunc options such as output placement and masking.
np.sin is a universal function that computes the trigonometric sine independently for each value in an array-like input. Inputs are interpreted as radians; scalar input produces a scalar result, while array input produces an array-shaped result. Optional ufunc controls can select output storage, masking, casting, dtype, memory order, and subclass behavior.
numpy.sin(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True [, signature])| Name | Type | Description |
|---|---|---|
x | array_like | Input angle(s), expressed in radians. |
out | ndarray, None, or tuple of ndarray and None, optional | Destination for the computed result; may be an ndarray, None, or a tuple containing an ndarray and None. |
where | array_like of bool, optional | Boolean condition selecting positions at which computation occurs. |
casting | {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional | Casting rule used by the ufunc. |
order | {‘K’, ‘C’, ‘F’, ‘A’}, optional | Memory layout order for the result. |
dtype | dtype, optional | Output data type. |
subok | bool, optional | Whether to pass through ndarray subclasses. |
signature | string, optional | Generalized-ufunc signature control. |
y, array_like — The sine of each element of x; this is a scalar if x is a scalar.
x.out argument can direct computed values into a supplied destination.import numpy as np
angles_degrees = np.array([0., 30., 45., 90.])
angles_radians = np.deg2rad(angles_degrees)
values = np.sin(angles_radians)
print(values)Converts degrees to radians, then computes the sine element-wise.
Compute sine values for one angle or many angles.
Apply sine to vectors or matrices without explicit Python loops.
Write results into a preallocated array.
Evaluate only selected array positions using a boolean condition.
np.sin compute, and what unit does it expect?np.sin is an element-wise trigonometric ufunc. Its input angle is measured in radians, and it returns the sine of each input element; scalar input produces a scalar.
Follow-up: How would you process degrees? Convert them to radians before calling np.sin, for example with np.deg2rad or multiplication by π/180.
out parameter?The out argument specifies where the result is stored. The documentation describes it as an ndarray, None, or a tuple containing an ndarray and None.
Follow-up: Why use out? It can let a caller reuse an existing destination array and avoid allocating a separate result.
where controls the positions where the ufunc computes values, while options such as dtype, casting, order, and subok control result computation and representation. The full signature exposes these as keyword-only controls.
Follow-up: What risk comes with masking via where and an uninitialized destination? Positions not selected for computation may retain whatever values were already present.
numpy.arcsinnumpy.sinhnumpy.cos