# Get the Trigonometric tangent of an array of angles given in degrees with Python

Trigonometric tangent is equivalent to np.sin(x)/np.cos(x) element-wise. To get the Trigonometric tangent of an array of angles given in degrees, use the numpy.tan() method in Python Numpy. The method returns the tangent of each element of the 1st parameter x. The 1st parameter, x, is an Angle, in radians (2pi means 360 degrees). Here, it is an array of angles.

The 2nd and 3rd parameters are optional. The 2nd parameter is an ndarray, A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.

The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.

## Steps

At first, import the required library −

import numpy as np

Array of angles to find tan 0, tan 30, tan 45, tan 60, tan 90, tan 180, tan -180 −

arr = np.array((0., 30., 45., 60., 90., 180., -180.))


Displaying our array −

print("Array...\n",arr)

Get the datatype −

print("\nArray datatype...\n",arr.dtype)


Get the dimensions of the Array −

print("\nArray Dimensions...\n",arr.ndim)

Get the number of elements of the Array −

print("\nNumber of elements in the Array...\n",arr.size)


To find the trigonometric tangent of an array of angles given in degrees, use the numpy.tan() method in Numpy −

print("\nResult...",np.tan(arr * np.pi / 180. ))

## Example

import numpy as np

# Trigonometric tangent is equivalent to np.sin(x)/np.cos(x) elementwise.
# To get the Trigonometric tangent of an array of angles given in degrees, use the numpy.tan() method in Python Numpy

print("The Trigonometric tangent of an array of angles...")

# Array of angles
# finding tan 0, tan 30, tan 45, tan 60, tan 90, tan 180, tan -180.
arr = np.array((0., 30., 45., 60., 90., 180., -180.))

# Display the array
print("Array...\n", arr)

# Get the type of the array
print("\nOur Array type...\n", arr.dtype)

# Get the dimensions of the Array
print("\nOur Array Dimensions...\n",arr.ndim)

# Get the number of elements in the Array
print("\nNumber of elements...\n", arr.size)

# To find the trigonometric tangent of an array of angles given in degrees, use the numpy.tan() method in Numpy
print("\nResult...",np.tan(arr * np.pi / 180. ))

## Output

The Trigonometric tangent of an array of angles...
Array...
[ 0. 30. 45. 60. 90. 180. -180.]

Our Array type...
float64

Our Array Dimensions...
1

Number of elements...
7

Result... [ 0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00
1.63312394e+16 -1.22464680e-16 1.22464680e-16]