Numpy Trigonometric Functions
Python, Numpy, Trignometry, Numpy trigonometric function

What is Numpy?
NumPy is a short form for Numerical Python, which is applied for scientific programming in Python, especially for numbers. It comprises multidimensional objects in arrays and a package of integrating tools for Python implementation. It is a mix of C and Python used as an alternative for traditionally used MATLAB programming, where data in the form of numerals are treated as arrays for multidimensional functions and rearrangement operations.
NumPy contains a large number of various mathematical operations. NumPy provides standard trigonometric functions, functions for arithmetic operations, handling complex numbers, etc.
What are NumPy trigonometric Functions?
NumPy consists of a large number of built-in mathematical functions that can solve mathematical problems. The in-built math module is imported for mathematical calculations.
It can perform trigonometric operations, rounding functions and can also handle complex numbers. NumPy mathematical functions include methods for exponential, logarithmic, and hyperbolic functions.
Here in this article, we’ll see some NumPy trigonometric functions.
Here is the outline of steps we’ll follow:
- Import the
numpy
- Calculate trigonometric values from radian
- Calculate trigonometric values from degree
- Inverse trigonometric functions
- Calculate hypotenuse
np.hypt()
You can view and execute the code for this tutorial here on Jovian a free code hosting platform:
Import the numpy
library
Numpy has standard trigonometric functions which return trigonometric ratios for a given angle in radians. A radian is a unit of measure for angles used mainly in trigonometry. It is used as an alternative to degrees. Whereas, in degrees, a full circle is 360 degrees, in radians a full circle is 2π radians:

Numpy library has values for several numerical constants including pi
. We can use numpy.pi
or np.pi
depending on how we import the library.
Math library also has the value for numerical content pi
we can use math.pi
to calculate the value of it.
- Numpy accepts the angles in radian by default as input and returns the trigonometric values.
- It has trigonometric functions np.sin(), np.cos() and np.tan() to calculate the values of sine, cosec, and tangent.
Calculate trigonometric values from radian
Let’s see the trigonometric table :

Calculate trigonometric values from degree
As we know NumPy trigonometric functions take input in radian, so here we will convert our angles in the degree to angles in radian using np.deg2rad() NumPy functions. then we can easily calculate the values.
In the above cell, we are converting an array of degrees into radians using deg2rad
functions of python and then getting the values for trigonometric functions. So it is important to use deg2rad
if we are using NumPy array as degree otherwise it will consider input in radian. We can see the trigonometric values are the same in both while calculating values from radian and degree.
Inverse trigonometric functions
- numpy has inverse trignometric functions like np.arcsin(), np.arcos(), and np.arctan()
- Inverse take the ratios and gives the angles
- Inverse trig functions do the opposite of the “regular” trig functions
Why are we getting 44.99999
instead of 45
?
- We can not track an infinite number of irrational digits in python.
- Python use floating-point representation rather than rational numbers.
- Floating-point numbers are represented in computer hardware as base 2 (binary) fractions.
- Most decimal fractions cannot be represented exactly as binary fractions. A consequence is that, in general, the decimal floating-point numbers you enter are only approximated by the binary floating-point numbers stored in the machine.
- Python documentation on floating-point limitations
So, that’s the reason we are getting approximated values for 45 degree
as 44.99999 degree
in above Inverse functions.
Rational Number — A Rational Number can be written as a ratio of two integers (ie a simple fraction).
Irrational Number — Irrational numbers are real numbers that cannot be represented as a simple fraction. It cannot be expressed in the form of a ratio, such as p/q, where p and q are integers, q≠0. It is a contradiction of rational numbers.
Pi (π) is an irrational number because it is non-terminating. The approximate value of pi is 22/7. Also, the value of π is 3.14159 26535 89793 23846 264…
Calculate hypotenuse np.hypt()
The hypt() returns an array containing values of the hypotenuse of the right-angle triangle. It returns a single value of both legs(side and perpendicular) are passed as scalar values.
The Pythagoras theorem states that if a triangle is right-angled (90 degrees), then the square of the hypotenuse is equal to the sum of the squares of the other two sides. In the given triangle ABC, we have AC2 = AB2 + BC2. Here, AB is the base, AC is the altitude or the height, and BC is the hypotenuse.

Example: A boy sees a bird sitting on a tree at an angle of elevation of 20°. If a boy is standing 10 meters away from the tree, at what height bird is sitting?

Solution: Consider ABC a right triangle, A is a bird’s location, B = tree is touching the ground, and C = boy’s location.
So BC 10 meter, angle C = 20° and let AB =?
We know, tan C = opposite side/adjacent side
tan(20°) = AB/10
or AB = 10 × tan(20°)
The bird is sitting at a height of 3.6 meters from the ground.
Conclusion
In this notebook, we have explained the NumPy trigonometric functions. Calculations of the angles and ratios in NumPy. a working example of the Pythagoras theorem.
Reference
- NumPy youtube video by AaKash N S
- Numpy official tutorial: https://numpy.org/doc/stable/user/quickstart.html
- Python documentation on Rational number
- What is Rational and Irrational number(Khan Academy)
- Python documentation on floating-point limitations
- https://data-flair.training/blogs/numpy-mathematical-functions