Created
February 15, 2019 13:32
-
-
Save Robofied/f0c64def0c20d22a08e7f70f9e9dbe10 to your computer and use it in GitHub Desktop.
Numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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