Instantly share code, notes, and snippets.

🏠
Working from home

# Joe Kingtonjoferkington

🏠
Working from home
• Sort options
Created Aug 28, 2015
Lovely dynamic typing
View silly.py
 import random class BadIdea(object): def __getattr__(self, key): return random.randint(0, 1000) def __setattr__(self, key, value): pass x = BadIdea()
Created Feb 21, 2014
I'm having a bit too much fun with this...
View yo_dawg.py
 import matplotlib.pyplot as plt import numpy as np def main(): t = np.linspace(0, 4*np.pi, 1000) fig, ax = plt.subplots() ax.plot(t, np.cos(t)) ax.plot(t, np.sin(t)) inception(inception(inception(fig)))
Created May 21, 2014
Outlines
View outline.py
 import scipy.ndimage as ndimage import numpy as np import matplotlib.pyplot as plt data = np.zeros((40,40), dtype=bool) data[5:20, 5:20] = True data[15:35, 15:35] = True footprint = np.ones((3,3)) outside = ndimage.binary_dilation(data, structure=footprint) - data
Last active Aug 29, 2015 — forked from anonymous/BenchMapCoordinates.py
View BenchMapCoordinates.py
 # -*- coding: utf-8 -*- """ Benchmark for spline interpolation of a 3D wind field, using the function map_coordinates. The spline interpolation is about 46000 times slower than a linear interpolation. It is also about 10000 times slower than an equivalent program, written in the programming language Julia. """ import time import numpy as np from scipy import ndimage
Created Oct 14, 2014
View gist:0b858cecc1ee659dd0d8
 pipeline = sklearn.pipeline.Pipeline([ ('Replace nans', preprocessing.Imputer(strategy='mean')), ('Scale data', preprocessing.StandardScaler()), ('Feature Selection', SelectPercentile(f_regression, percentile=60)), ('Regression', ensemble.ExtraTreesRegressor( n_estimators=550,
Created Dec 2, 2014
View dashed_contours.py
 import numpy as np import matplotlib.pyplot as plt x, y = np.mgrid[:10, :10] z = np.hypot(x - 4.5, y - 4.5) #-- Create two masked arrays, one with the upper region and one with the lower. z1 = np.ma.masked_where(y > 5, z) # If we just invert the previous masked region, we'll have a gap. There are # better ways to do this, but for simple cases, we can just ensure a one-pixel
Created Jan 6, 2015