numpy.atan() function is same as numpy.arctan() function.
NumPy atan()
The numpy.atan()
function computes the trigonometric inverse tangent (arctangent) of each element in an input array.
The inverse tangent function returns values in the range [-π/2, π/2]
.
Syntax
numpy.atan(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)
Parameters
Parameter | Type | Description |
---|---|---|
x | array_like | Input values for which the inverse tangent is 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 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 inverse tangent values of the input elements. If the input is a scalar, a scalar is returned.
The output values are in the range [-π/2, π/2]
.
Examples
1. Computing Arctangent of a Single Value
Here, we compute the inverse tangent of a single value.
import numpy as np
# Define a value
value = 1.0
# Compute the inverse tangent (arctan) of the value
result = np.atan(value)
# Print the result
print("Arctan of 1:", result)
Output:
Arctan of 1: 0.7853981633974483

The result is approximately 0.785
, which is equivalent to π/4
.
2. Computing Arctangent for an Array of Values
We compute the arctangent values for multiple input values in an array.
import numpy as np
# Define an array of values
values = np.array([-1, 0, 1, np.tan(np.pi/3)])
# Compute the inverse tangent of each value
arctan_values = np.atan(values)
# Print the results
print("Input values:", values)
print("Arctan values:", arctan_values)
Output:
Input values: [-1. 0. 1. 1.73205081]
Arctan values: [-0.78539816 0. 0.78539816 1.04719755]

The results show that atan(-1)
is -π/4
, atan(0)
is 0
, atan(1)
is π/4
, and atan(√3)
is π/3
.
3. Using the out
Parameter
Using an output array to store results instead of creating a new array.
import numpy as np
# Define an array of values
values = np.array([-1, 0, 1])
# Create an output array with the same shape
output_array = np.ndarray(shape=[1, 3])
# Compute arctan and store the result in output_array
np.atan(values, out=output_array)
# Print the results
print("Computed arctan values:", output_array)
Output:
Computed arctan values: [-0.78539816 0. 0.78539816]

4. Using the where
Parameter
Using a condition to compute arctangent only for selected elements.
import numpy as np
# Define an array of values
values = np.array([-1, 0, 1, 10])
# Define a mask (compute arctan only where mask is True)
mask = np.array([True, False, True, False])
# Compute arctan values where mask is True
result = np.atan(values, where=mask)
# Print the results
print("Computed arctan values with mask:", result)
Output:
Computed arctan values with mask: [-7.85398163e-001 0.00000000e+000 7.85398163e-001 4.95242130e+223]

The arctangent is computed only for elements where mask=True
. The other values remain unchanged.