Trigonometric calculations
Converting angular measurements into slope ratios.
NumPy · Function
Computes tangent element-wise for array-like input, using radians. It returns corresponding tangent values and supports NumPy ufunc options such as output reuse and conditional computation.
np.tan applies the tangent function independently to each input value. Inputs are interpreted in radians, and array inputs are processed element by element with normal NumPy broadcasting behavior.
numpy.tan(*x*, /, *out=None*, ***, *where=True*, *casting='same_kind'*, *order='K'*, *dtype=None*, *subok=True* [, *signature*])| Name | Type | Description |
|---|---|---|
x | array_like | Array-like values whose tangents are computed. |
out | ndarray, None, or tuple of ndarray and None | Optional destination array or tuple of destinations for the result. |
where | array_like of bool, optional | Boolean condition selecting where computation occurs. |
casting | {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional | Casting rule used when converting operands. |
order | {‘K’, ‘A’, ‘C’, ‘F’}, optional | Memory layout order for the output. |
dtype | dtype, optional | Output data type. |
subok | bool, optional | Whether subclasses are allowed to pass through. |
ndarray containing the corresponding tangent values; a scalar when x is scalar.
out array must accommodate the broadcasted shape of the input.out, the destination is mutated and the returned object refers to that destination.import numpy as np
angles = np.array([0.0, np.pi / 4, np.pi / 2])
result = np.tan(angles)
print(result)Computes tangent independently for each angle in radians.
Converting angular measurements into slope ratios.
Applying tangent to a vector or matrix of angles.
Writing results into reusable memory.
np.tan compute?np.tan is a NumPy ufunc that computes tangent element by element. Its input is interpreted in radians, and the result has the corresponding tangent values.
Follow-up: What happens for a scalar input? It returns a scalar rather than a one-element array.
out parameter work?The out argument supplies the destination array. It must be compatible with the broadcast shape of the inputs; when supplied, the function writes into it and returns a reference to it.
Follow-up: Why might out be useful? It can avoid allocating a new result array when reusing storage matters.
The function accepts array-like input and supports optional where, casting, order, dtype, and subok controls inherited from the ufunc interface. The result is computed element-wise.
Follow-up: How would you restrict computation to selected elements? Pass a Boolean where mask and provide initialized output storage for positions not selected.
numpy.sinnumpy.cosnumpy.arctannumpy.tanh