from brian import * import time import pickle import joblib import gc def brianreset(): clear(True,True) gc.collect() defaultclock.t = 0*second %%timeit for i in range(1000): for j in range(1000): i*j %%timeit for i in xrange(1000): for j in xrange(1000): i*j A = rand(100000) B = rand(100000) %%timeit for a, b in zip(A, B): a*b import itertools %%timeit for a, b in itertools.izip(A, B): a*b import pickle obj = ['a', 'list', 'of', 'words'] pickle.dump(obj, open('alistofwords.pkl', 'wb'), -1) newobj = pickle.load(open('alistofwords.pkl', 'rb')) print ' '.join(newobj) import shelve shelf = shelve.open('test.shelf') shelf['meaning'] = 42 shelf.close() newshelf = shelve.open('test.shelf') print newshelf['meaning'] from collections import namedtuple paramA = linspace(0, 1, 10) paramB = linspace(0, 1, 10) trials = [] Trial = namedtuple("Trial", ['a', 'b', 'spikes']) for i in xrange(100): a = paramA[randint(len(paramA))] b = paramB[randint(len(paramB))] r = (a-0.5)**2+(b-0.5)**2 spikes = rand(int(r*100)) trials.append(Trial(a=a, b=b, spikes=spikes)) from collections import defaultdict counts = defaultdict(int) numtrials = defaultdict(int) for trial in trials: counts[trial.a, trial.b] += len(trial.spikes) numtrials[trial.a, trial.b] += 1 rates = dict() for a, b in counts.keys(): rate = counts[a,b]*1.0/numtrials[a,b] plot([a], [b], 'o', ms=rate, c='k') rates[a, b] = rates pickle.dump(rates, open('rates.pkl', 'wb'), -1) a = linspace(0, 1, 100) b = linspace(0, 1, 100) def getimg(): img = zeros((100, 100)) for i in xrange(100): for j in xrange(100): img[i, j] = (a[i]-0.5)**2+(b[j]-0.5)**2 return img def getimg_vectorised(): return (a[:, newaxis]-0.5)**2+(b[newaxis, :]-0.5)**2 subplot(121) imshow(getimg()) subplot(122) imshow(getimg_vectorised()) %timeit getimg() %timeit getimg_vectorised() delta = 0.005 train1 = sort(rand(50)) train2 = sort(rand(55)) def cf_loop(): num_coinc = 0 for t1 in train1: for t2 in train2: if abs(t1-t2)