Last active
July 17, 2017 15:13
-
-
Save loren138/3c9246f2210c0233a72bda58732e4f8b to your computer and use it in GitHub Desktop.
Example Python
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
from __future__ import print_function | |
import numpy as np | |
import matplotlib.pyplot as plt #conda install matplotlib | |
# -40 65.33333333 | |
# -30 99.66666667 | |
# -20 130 | |
# -10 175.3333333 | |
# 0 383.6666667 | |
# 10 446.3333333 | |
# 20 642.6666667 | |
# 30 716.6666667 | |
# 40 717.6666667 | |
# 50 706.3333333 | |
# 60 626 | |
# 70 536.3333333 | |
# 80 365.3333333 | |
# 90 31.66666667 | |
myRange = np.random.rand(10000000) | |
mySum = 0 | |
#for number in myRange: | |
# mySum += number | |
mySum = myRange.sum() | |
print(mySum) | |
x = [1, 2, 4, 8] | |
y = [10, 40, 80, 20] | |
result = np.polyfit(x, y, 2) | |
eq = np.poly1d(result) | |
print(eq) | |
print(eq(2)) | |
myX = 4 | |
myY = eq(myX) | |
print(myY) | |
x2 = np.arange(-40, 90) | |
yfit = np.polyval(result, x2) | |
#print(yfit) | |
plt.plot(x, y, label = "Points") | |
plt.plot(x2, yfit, label = "Fit") | |
#plt.show() | |
plt.savefig('example.png') | |
myString = 'asnutoh' | |
if myString.isalpha(): | |
print('alpha') | |
elif myString.isdigit(): | |
print('digit') | |
else: | |
print('neither') | |
number = 0 | |
try: | |
number = float(myString) | |
except ValueError: | |
print('Exception Happened') | |
print(number*2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment