Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Numpy
import numpy as np
## 1. np.sin()
print(np.sin(np.pi/2.))
#[Output]:
#1.0
"""In this we are taking an array of angles in degree and calculating the sine of that, so we are converting
them to radians first"""
print(np.sin(np.array((0., 30., 45., 60., 90.)) * np.pi / 180. ))
#[Output]:
#array([0. , 0.5 , 0.70710678, 0.8660254 , 1. ])
## 2. np.cos()
## Similarly we can calulate cosine and tan of angles(degrees or radians)
print(np.cos(np.array((0., 30., 45.)) * np.pi / 180. ))
#[Output]:
#array([1. , 0.8660254 , 0.70710678])
## 3. deg2rad function for converting degree to radians
print(np.deg2rad(180))
#[Output]:
#3.141592653589793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.