4 Universal NumPy Trigonometric functions

Filed Under: NumPy
Universal Numeric Trigonometric Functions

Hey, readers! In this article, we will be focusing on 4 Universal Numeric Trigonometric functions, in detail.

So, let us begin!! 馃檪

Also read: Numpy Universal functions

Universal NumPy Trigonometric functions

With Universal functions, we can operate on complex data operations based on the NumPy Array class enabling us to perform element wise operations and manipulations based on element rather than the entire array at once.

In the context of this topic, we will be having a look at the below functions under the Universal NumPy Trigonometric section:

  1. Trigonometric method
  2. Hypotenuse
  3. Hyperbolic functions
  4. Inter-conversion between degree and radian angles

1. Trigonometric methods

When it comes to NumPy trigonometric functions, we can think about sine, cos, tan, etc as studied in the earlier grades. Based on that scenario, we will be having a look at the below trigonometric functions-

  1. numpy.sin() function: expresses sine component
  2. numpy.cos() function: expresses cosine component
  3. numpy.tan() function: expresses tangent component


import numpy as np
ar = np.array([15,60,45])
sin = np.sin(ar)
print("Sine value",sin)
cos = np.cos(ar)
print("Cosine value",cos)
tan = np.tan(ar)
print("Tangent value",tan)


Sine value [ 0.65028784 -0.30481062  0.85090352]
Cosine value [-0.75968791 -0.95241298  0.52532199]
Tangent value [-0.8559934   0.32004039  1.61977519]

2. Hypotenuse

Do you remember calculating hypotenuse value using Pythagora’s theorem? Now, that overhead is no more, haha! 馃檪

The numpy.hypot() function enables us to calculate the hypotenuse score for the right-angled triangle provided that we have base and height values in place as parameters.


numpy.hypot(base, height) 


In the below example, we have provided the base and height values to the hypot() function to get the hypotenuse score.

import numpy as np
b = 2
h = 4
hy = np.hypot(b, h)



3. Hyperbolic functions

Apart from Basic trigonometric functions, NumPy provides us with the below functions to calculate the hyperbolic score for the basic trigonometric terms such as sine, cosine, etc.


In the below example, we have calculated the hyperbolic sine, cosine and tangent score for all the elements present in the array.

import numpy as np
ar = np.array([15,60,45])
sin = np.sinh(ar)
print("Hyperbolic Sine value",sin)
cos = np.cosh(ar)
print("Hyperbolic Cosine value",cos)
tan = np.tanh(ar)
print("Hyperbolic Tangent value",tan)


Hyperbolic Sine value [1.63450869e+06 5.71003695e+25 1.74671355e+19]
Hyperbolic Cosine value [1.63450869e+06 5.71003695e+25 1.74671355e+19]
Hyperbolic Tangent value [1. 1. 1.]

4. Inter-conversion between the degree and radian angles

Gone are the days when we need a calculator to get the data values converted from degree to radians and vice versa.

I personally recall myself memorizing the inter-conversions of the standard angles for my mathematics examination.

It is not the same case now. Even if we plan an assignment and we need the value of angles in degrees and radian at different places within the application/code, we can achieve the same using the below functions-

  1. deg2rad: Converts a degree value of an angle to radians.
  2. rad2deg: Converts radian angle to a degree.


import numpy as np
ar = np.array([15,60,45])
rad = np.deg2rad(ar)
print("Degree to Radian conversion:", rad)
#arr_rad = np.array([0.52359878, 1.04719755, 1.57079633])
degree = np.rad2deg(ar)
print("Radian to degree conversion:", degree)


Degree to Radian conversion: [0.26179939 1.04719755 0.78539816]
Radian to degree conversion: [ 859.4366927  3437.74677078 2578.31007809]


By this, we have come to the end of the NumPy Trigonometric functions article. Feel free to comment below, in case you come across any questions.

For more such posts related to聽Python programming, Stay tuned with us!

Generic selectors
Exact matches only
Search in title
Search in content