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
def to_sparse(p_dense): | |
states = numpy.indices(numpy.shape(p_dense)) | |
p_sparse = {} | |
for state in states.transpose(): | |
state = tuple(state) | |
probability = p_dense[state] | |
if probability > 0: | |
p_sparse[state] = p_dense[state] | |
return p_sparse |
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 cmepy.solver | |
def do_something_fancy(y): | |
""" | |
transforms the solution y in some interesting and useful manner | |
""" | |
return y # TODO IMPLEMENT ME | |
class FancySolver(object): |
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
# leads to a segfault in version 1.2.1 | |
import numpy | |
bad = (numpy.array([0]), numpy.array(0)) | |
numpy.asarray(bad) |
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
b = ['b = ', "print('%s' % str(x[0]), end='')", '\n', 'def f(*x): eval(b[1]) if type(x[0]) is str else [g(s) for s in x]', "def g(x): print('f(b[%d])' % x if type(x) is int else 'f(%s)' % x)", "0, 'b', 4, 2, 3", '2, b[5], b[6]'] | |
def g(x): print('f(b[%d])' % x if type(x) is int else 'f(%s)' % x) | |
def f(*x): eval(b[1]) if type(x[0]) is str else [g(s) for s in x] | |
f(b[0]) | |
f(b) | |
f(b[4]) | |
f(b[2]) | |
f(b[3]) | |
f(b[2]) | |
f(0, 'b', 4, 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
a = "for x in ('a = '+repr(a), a): print(x)" | |
for x in ('a = '+repr(a), a): print(x) |
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
""" | |
Plot x,y pairs from csv file. | |
usage: | |
python plot_csv.py xy_data.csv | |
csv format: | |
assume no header row |
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
CRIME_DATA_URL := http://archive.ics.uci.edu/ml/machine-learning-databases/communities/communities.data | |
CRIME_DATA := crime.data | |
test: $(CRIME_DATA) | |
time python test_ridge_crime.py $^ | |
.PHONY: test | |
$(CRIME_DATA): | |
wget -O $@ $(CRIME_DATA_URL) |
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
def exchange(a, i, j): | |
a[i], a[j] = a[j], a[i] | |
def partition(a, x): | |
n = len(a) | |
i = 0 | |
j = 0 | |
k = n | |
while j < k: | |
if a[j] < x: |
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
on ubuntu... | |
sudo apt-get install xsel | |
then from inside vim to copy the contents of the current file to clipboard | |
! xsel -b < % |
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
""" | |
python & numpy port of james hague's blog post 141 | |
ref: | |
http://prog21.dadgum.com/141.html | |
""" | |
import numpy | |
a = numpy.array([10, 5, 9, 6, 20, 17, 1]) |
OlderNewer