Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 15, 2019 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/f0c64def0c20d22a08e7f70f9e9dbe10 to your computer and use it in GitHub Desktop.
Save Robofied/f0c64def0c20d22a08e7f70f9e9dbe10 to your computer and use it in GitHub Desktop.
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