Created
July 16, 2015 18:21
-
-
Save neale/acde7c0ffb1d53918df1 to your computer and use it in GitHub Desktop.
yee
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 rolling_apply_slow(a, w): | |
print len(a) | |
"""applys a function to a window slowly b/c python loops != c loops""" | |
r = np.empty(a.shape) | |
r.fill(np.nan) | |
for i in range(w-1, a.shape[0]): | |
r[i] = max(a[(i-w+1):i+1]) | |
print len(r) | |
return r | |
def rolling_window(data, window): | |
"""way faster, applys a strided (moving) window over the array""" | |
shape = data.shape[:-1] + (data.shape[-1] - window + 1, window) | |
strides = data.strides + (data.strides[-1],) | |
return np.lib.stride_tricks.as_strided(data, shape=shape, strides=strides) | |
y = lowess_smooth(xdata, ydata, .25, 2) | |
m = np.amax(rolling_window(y, 2*w+1), 1) | |
idx = np.delete(y, [(n-1) - i for i in xrange(len(y[:w]))], None) | |
delta = np.array((filter(lambda x: x not in idx[:w], idx))) | |
delta = m - delta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment