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 | |
a = np.arange(6).reshape((3,2)) | |
print(a) | |
#[Output]: | |
#array([[0, 1], | |
# [2, 3], | |
# [4, 5]]) |
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
print(np.cos(np.deg2rad(np.array((0.,30.,45.))))) | |
#[Output]: | |
#array([1. , 0.8660254 , 0.70710678]) |
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""" |
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
## 1. moveaxis routine | |
import numpy as np | |
x = np.zeros((3, 4, 5)) | |
## In this all the elements shape gets shifted in the direction of source to destonation, so for this example | |
## it is just like cyclic rotation in clockwise direction. | |
print(np.moveaxis(x, 0, -1).shape) | |
#[Output]: |
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 | |
a = np.arange(6) | |
print(a) | |
#[Output]: | |
#[0 1 2 3 4 5] | |
## 1. Reshaping | |
a.reshape(2,3) |
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
## Here order doesn't matter | |
a = np.arange(6).reshape(2,3) | |
for x in np.nditer(a, order='F'): | |
print (x,end=",") | |
#[Output]: | |
#0,3,1,4,2,5, |
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 | |
a = np.arange(6).reshape(2,3) | |
for x in np.nditer(a): | |
print (x,end=",") | |
#[Output]: | |
#0,1,2,3,4,5, |
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
## Let us consider an example in which we need to calculate the % of calories from carb, protein, fat in different foods | |
## Each colum represent to new food like col1-> food1(apple), col2-> food2(orange) , col3-> food3(banana) =, col4->food4(mango) | |
## Rows represent of as-: row1->carb ,row2->protein ,row3->fat | |
import numpy as np | |
A =np.array([[56.0,0.0,4.4,68.0], | |
[1.2,104.0,52.0,8.0], | |
[1.8,135.0,99.0,0.9]]) | |
print(A) |
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 | |
x = np.arange(35) | |
print(x) | |
#[Output]: | |
#[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
# 24 25 26 27 28 29 30 31 32 33 34] | |
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 | |
x = np.arange(10,1,-1) | |
print(x) | |
#[Output]: | |
#[10 9 8 7 6 5 4 3 2] | |
print(x[np.array([3,3,4,7])]) |