This file contains hidden or 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
| ''' create object using numpy to read CSV. creates one variable per column | |
| so you can use f.col_name instead of f.data['col_name'] | |
| f = NamedCSV(filename) | |
| f.data # all data in the file in an np recarray | |
| f.mass | |
| f.data['mass'] # same as previous line | |
| f.extract(f.mass > 180) | |
| ''' |
This file contains hidden or 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 inspect import getsource | |
| import re | |
| def psource(fun): | |
| print(re.sub('""".*"""', '', getsource(fun), flags=re.DOTALL)) | |
| #example | |
| from somewhere import foo | |
| psource(foo) |
This file contains hidden or 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 | |
| import numpy as np | |
| from mpl_toolkits.mplot3d import Axes3D | |
| xs = np.linspace(-4, 4, n) | |
| ys = np.linspace(-4, 4, n) | |
| X, Y = np.meshgrid(xs, ys) | |
| # mixture of Gaussians - based on Matlab peaks() function |
This file contains hidden or 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
| void foo1(HANDLE start, HANDLE end, vector<Data>* data_queue, int index) | |
| { | |
| int id = index; | |
| vector<Data>* data = data_queue; | |
| while (true) { | |
| WaitForSingleObject(start, INFINITE); | |
| ResetEvent(start); | |
| Data& d = (*data)[index++]; | |
| if (index >= data->size()) |
This file contains hidden or 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
| dbeta (.7, 1, 2) | |
| from scipy.stats import beta | |
| beta(1, 2).pdf(.7) # frozen form, very slow if only calling once!!!!!! | |
| beta.pdf(.7, 1, 2) | |
This file contains hidden or 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
| # style the notebook | |
| from IPython.core.display import HTML | |
| import urllib.request | |
| # this link is to my Kalman filter book CSS file. | |
| response = urllib.request.urlopen('http://bit.ly/1LC7EI7') | |
| HTML(response.read().decode("utf-8")) |
This file contains hidden or 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 | |
| ax = plt.gca() | |
| ax.set_aspect('equal') | |
| plt.xlim(-4, 4) | |
| plt.ylim(0, 8) |
This file contains hidden or 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
| # draw the figure so the animations will work | |
| import matplotlib.pyplot as plt | |
| fig = plt.gcf() | |
| fig.show() | |
| fig.canvas.draw() | |
| while True: | |
| # compute something | |
| plt.plot([1, 2, 3, 4, 5], [2, 1, 2, 1, 2]) # plot something | |
This file contains hidden or 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 sympy.abc import x, y, z | |
| from sympy.plotting import plot, plot3d | |
| import sympy as sp | |
| fron sympy import solve, Eq | |
| def plot_line(e): | |
| e = solve(e, y) | |
| plot(e[0]) | |
This file contains hidden or 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
| def triangle_angles(p0, p1, p2): | |
| A = p1 - p0 | |
| B = p2 - p1 | |
| C = p0 - p2 | |
| angles = [] | |
| for e1, e2 in ((A,-B), (B,-C), (C,-A)): | |
| num = np.dot(e1, e2) | |
| denom = np.linalg.norm(e1) * np.linalg.norm(e2) | |
| angles.append(np.arccos(num/denom)) | |
| return angles |