Get the Trigonometric tangent of an angle in Python

PythonNumpyServer Side ProgrammingProgramming

Trigonometric tangent is equivalent to np.sin(x)/np.cos(x) element-wise. To find the Trigonometric tangent of an angle, use the numpy.tan() method in Python Numpy. The method returns the sine of each element of the 1st parameter x. This is a scalar if is a scalar. The 1st parameter, x, is an Angle, in radians (2pi means 360 degrees). 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 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

Get the Trigonometric tangent. Finding tangent 90 degrees −

print("\nResult...",np.tan(np.pi/2.))

Finding tangent 60 degrees −

print("\nResult...",np.tan(np.pi/3.))

Finding tangent 45 degrees −

print("\nResult...",np.tan(np.pi/4.))

Finding tangent 30 degrees −

print("\nResult...",np.tan(np.pi/6.))

Finding tangent 0 degrees −

print("\nResult...",np.tan(0))

Finding tangent 180 degrees −

print("\nResult...",np.tan(np.pi))

Finding tangent -180 degrees −

print("\nResult...",np.tan(-np.pi))

Example

import numpy as np

# Trigonometric tangent is equivalent to np.sin(x)/np.cos(x) elementwise.
# To find the Trigonometric tangent of an angle, use the numpy.tan() method in Python Numpy
print("Get the Trigonometric tangent...")

# finding tangent 90 degrees
print("\nResult...",np.tan(np.pi/2.))

# finding tangent 60 degrees
print("\nResult...",np.tan(np.pi/3.))

# finding tangent 45 degrees
print("\nResult...",np.tan(np.pi/4.))

# finding tangent 30 degrees
print("\nResult...",np.tan(np.pi/6.))

# finding tangent 0 degrees
print("\nResult...",np.tan(0))

# finding tangent 180 degrees
print("\nResult...",np.tan(np.pi))

# finding tangent -180 degrees
print("\nResult...",np.tan(-np.pi))

Output

Get the Trigonometric tangent...

Result... 1.633123935319537e+16

Result... 1.7320508075688767

Result... 0.9999999999999999

Result... 0.5773502691896257

Result... 0.0

Result... -1.2246467991473532e-16

Result... 1.2246467991473532e-16
raja
Updated on 25-Feb-2022 06:05:25

Advertisements