# Numpy tan – Python NumPy tan() Function

### Numpy Module:

Numpy tan: NumPy is a Python module that is used to work with arrays.

It also has functions for working with linear algebra, the Fourier transform, and matrices.

Travis Oliphant designed NumPy in 2005. It is an open-source project that you are free to use.

NumPy is an abbreviation for Numerical Python.

### Uses of NumPy Module:

Numpy tangent: Lists in Python serve the same purpose as arrays, although they are slower to process.

NumPy’s goal is to provide array objects that are up to 50 times faster than ordinary Python lists.

The array object in NumPy is named ndarray, and it comes with a slew of helper methods that make working with ndarray a breeze.

Arrays are often utilized in data science, where speed and resources are critical.

### NumPy tan() Function:

np.tan: The NumPy tan() function computes the trigonometric tangent of an angle in radians.

Syntax:

numpy.tan(array, out=None)

Parameters

array: This is required.The items of the array whose tangent values are to be calculated.
out: This is optional. The output array’s shape. It specifies the location where the result will be saved. If given, it must have a shape to which the inputs are broadcast to. If not given or None, a freshly-allocated array is returned.

## NumPy tan() Function in Python

### Method #1: Using Built-in Functions (Static Input)

Approach:

• Import numpy module using the import keyword.
• Pass some random list of angles as an argument to the array() function to create an array. Store it in a variable.
• Convert the above-given array angles to radians using numpy.pi/180.
• Store it in another variable.
• Get the tangent values of the above array angles using the tan() function of numpy module and store it in another variable.
• Print the tangent values of the above-given array angles.
• The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random list of angles as an argument to the array() function to
# create an array. Store it in a variable.
gvn_arry = np.array([180, 45, 0, 90])
# Convert the above given array angles to radians using numpy.pi/180
# Store it in another variable.
gvn_arry = gvn_arry*np.pi/180
# Get the tangent values of the above array angles using the tan() function of
# numpy module and store it in another variable.
rslt= np.tan(gvn_arry)
# Print the tangent values of the above given array angles
print("The tangent value of above given array angles = \n", rslt)



Output:

The tangent value of above given array angles =
[-1.22464680e-16 1.00000000e+00 0.00000000e+00 1.63312394e+16]

### Method #2: Using Built-in Functions (User Input)

Approach:

• Import numpy module using the import keyword.
• Give the list as user input using the list(),map(),split(),int functions and store it in a variable.
• Pass the above list as an argument to the array() function to create an array. Store it in a variable.
• Convert the above-given array angles to radians using numpy.pi/180.
• Store it in another variable.
• Get the tangent values of the above array angles using the tan() function of numpy module and store it in another variable.
• Print the tangent values of the above-given array angles.
• The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Give the list as user input using the list(),map(),split(),int
# functions and store it in a variable.
gvn_lst = list(map(int, input(
'Enter some random List Elements separated by spaces = ').split()))
# Pass the above list as an argument to the array() function to create an array.
# Store it in a variable.
gvn_arr = np.array(gvn_lst)
# Convert the above given array angles to radians using numpy.pi/180
# Store it in another variable.
gvn_arry = gvn_arry*np.pi/180
# Get the tangent values of the above array angles using the tan() function of
# numpy module and store it in another variable.
rslt= np.tan(gvn_arry)
# Print the tangent values of the above given array angles
print("The tangent value of above given array angles = \n", rslt)



Output:

Enter some random List Elements separated by spaces = 45 120 0 30
The tangent value of above given array angles =
[0.05488615 0.01370864 0. 0.02742244]