What is numpy.tan() in Python?

The numpy.tan() method in Python returns the tangent of a list of numbers. This is equal to numpy.sin(x) / numpy.cos(x).

The visual representation of the tangent (tantan) is as follows.

Visual represenation of tan

Syntax

numpy.tan(x, out=None)

Input parameters

  • x: This method takes an array of numbers as the input.
  • out=None: This is an optional parameter in numpy.tan() function. This could be ndarray, None, or tuple of the ndarray. This parameter identifies a location where the solution is stored.

Returns

This method returns a ndarray containing the tangent values of radian numbers from the input. The output may be scalar if the input is scalar.

Code example

import numpy as np
# Creating an array
array = np.array([0, np.pi/2, np.pi])
#Calculating the tangent of the values
result = np.tan(array)
#Using the out parameter
new_result = np.array([0, np.pi/2, np.pi])
np.tan(array, out = new_result)
print("Tengant of values : ", result)
print("New Result array : ", new_result)

Explanation

  • Line 3: We create an array using the np.array method.
  • Line 6: We calculate the tangent of the values in the array.
  • Line 9: We create a new array.
  • Line 10: We calculate the tangent values and store them in the new_result array using the out parameter.

Note: Providing the out parameter in numpy.tan() function stores the result in the out parameter and returns a reference to it.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved