Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.sin

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.

How it works

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.

Syntax

numpy.sin(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True [, signature])

Parameters

NameTypeDescription
xarray_likeInput angle(s), expressed in radians.
outndarray, None, or tuple of ndarray and None, optionalDestination for the computed result; may be an ndarray, None, or a tuple containing an ndarray and None.
wherearray_like of bool, optionalBoolean condition selecting positions at which computation occurs.
casting{‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optionalCasting rule used by the ufunc.
order{‘K’, ‘C’, ‘F’, ‘A’}, optionalMemory layout order for the result.
dtypedtype, optionalOutput data type.
subokbool, optionalWhether to pass through ndarray subclasses.
signaturestring, optionalGeneralized-ufunc signature control.

Returns

y, array_like — The sine of each element of x; this is a scalar if x is a scalar.

Key points

  • Computes the trigonometric sine independently for every input element.
  • The returned values correspond position-for-position to the elements of x.
  • Scalar and array-like inputs preserve the corresponding scalar or array-like result form.
  • The optional out argument can direct computed values into a supplied destination.

Common mistakes

  • A scalar input returns a scalar, whereas array-like input returns array-like output.

Example: Sine of angles

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.

When to use it

Trigonometric evaluation

Compute sine values for one angle or many angles.

Array-wide transformation

Apply sine to vectors or matrices without explicit Python loops.

Controlled output storage

Write results into a preallocated array.

Masked computation

Evaluate only selected array positions using a boolean condition.

Interview questions

QWhat does 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.

QWhat is the purpose of the 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.

QWhich keyword-only controls does the ufunc signature expose?

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.arcsin
  • numpy.sinh
  • numpy.cos

Source: numpy.sin — NumPy v2.6 Manual. Checked 2026-10-15.