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
#Example #1 - numpy version | |
import numpy as np | |
np.version.version | |
#Shift+Enter Command | |
#Example #2 - Vector of 10 null elements | |
import numpy as np | |
x = np.zeros(10) | |
x | |
#Example #3 - one element not null | |
import numpy as np | |
x = np.zeros(10) | |
x[4] = 1 | |
x | |
#Example #4 - vector of range of values | |
import numpy as np | |
x = np.arange(10,49,1) | |
x | |
#Example #5 - Reverse Vector | |
import numpy as np | |
x = np.arange(10,49,1) | |
xrev = x[::-1] | |
xrev | |
#Example #6 - 3 x 3 matrix | |
#[0..8] | |
import numpy as np | |
a = np.matrix('0,1,2;3,4,5;6,7,8') | |
a | |
#Example #7 - Indices of non zero elements | |
import numpy as np | |
a = [1,2,0,0,4,0] | |
aval = np.nonzero(a)[0] | |
print(aval) | |
#Example #8 - 3 x 3 Identity matrix | |
import numpy as np | |
a = np.eye(3, dtype=int) | |
a | |
#Example #9 - 3 x 3 x 3 array of random values | |
import random | |
import numpy as np | |
n = 3 | |
a = np.random.random((n,n,n)) | |
a | |
#Also found this link are doing the exercise - http://www.labri.fr/perso/nrougier/teaching/numpy.100/ |
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 matplotlib.pyplot as plt | |
#Declare Dictionary | |
result = {} | |
#Populate Data | |
for i in range(1,100,1): | |
result[i] = (i,i*9) | |
#Approach #1 | |
print 'Approach #1' | |
for i in range(1,100,1): | |
(key,value) = result[i] | |
print(key) | |
print(value) | |
#Approach #2 | |
print 'Approach #2' | |
for key, value in result.iteritems(): | |
print key | |
print value[1] | |
#Plot the line | |
def plotgraph(result): | |
for key, value in result.iteritems(): | |
print key | |
print value[1] | |
plt.plot(key, value[1],'-o') | |
plt.xlabel("x Values") | |
plt.ylabel("Y Value") | |
plt.title("Plot Graph") | |
plt.show() | |
plotgraph(result) |