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 specialist_function_factory(func, *s_args, **s_kwargs): | |
def specialist_func(*args, **kwargs): | |
all_args = s_args + args | |
all_kwargs = dict(list(s_kwargs.items()) + list(kwargs.items())) | |
return func(*all_args, **all_kwargs) | |
return specialist_func |
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 math | |
def num_fmt(num): | |
i_offset = 24 # change this if you extend the symbols!!! | |
prec = 3 | |
fmt = '.{p}g'.format(p=prec) | |
symbols = ['Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'k', '', 'm', 'u', 'n'] | |
e = math.log10(abs(num)) |
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
""" | |
>>> I = ai(start=0, step=1) | |
>>> I() | |
0 | |
>>> I() | |
1 | |
>>> J = ai(start=0, step=1) | |
>>> J() | |
0 | |
>>> I() |
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
""" | |
>>> I = ai(start=0, step=1) | |
>>> I() | |
0 | |
>>> I() | |
1 | |
>>> J = ai(start=0, step=1) | |
>>> J() | |
0 | |
>>> I() |
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
# Auto-incremented number, starting at 0. | |
# Relies on function defualts being evaluated only once and lists being mutable. | |
def ipp(__i=[-1]): | |
'''This is a dirty hack''' | |
__i[0] += 1 | |
return __i[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 GCD(a, b): | |
if b: | |
return GCD(b, a % b) | |
return a |
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
library(stats) | |
library(ggplot2) | |
set.seed(1) | |
# for our first example, let's create some synthetic easy-to-cluster data | |
d <- data.frame() | |
d <- rbind(d, data.frame(x=1 + rnorm(20, 0, 0.1), y=1 + rnorm(20, 0, 0.1), label=as.factor(rep(1, each=20)))) | |
d <- rbind(d, data.frame(x=1 + rnorm(20, 0, 0.1), y=3 + rnorm(20, 0, 0.1), label=as.factor(rep(2, each=20)))) | |
d <- rbind(d, data.frame(x=3 + rnorm(20, 0, 0.1), y=1 + rnorm(20, 0, 0.1), label=as.factor(rep(3, each=20)))) | |
d <- rbind(d, data.frame(x=3 + rnorm(20, 0, 0.1), y=3 + rnorm(20, 0, 0.1), label=as.factor(rep(4, each=20)))) |
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
class SlicerClass(object): | |
''' | |
slicerClass allows the creation of a slicer object. | |
A slicer, when indexed with square brackets, will return a slice object. | |
This allows a slice to be created and neatly passed as an argument. | |
''' | |
def __getitem__(self,val): | |
return val | |
def __len__ (self): | |
return 0 |
NewerOlder