Created
March 23, 2016 01:54
-
-
Save syrte/b5da1ee6e4a7661064c6 to your computer and use it in GitHub Desktop.
Return mean value of adjacent member of an array. Useful for plotting bin counts.
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 mid(x, base=None): | |
'''Return mean value of adjacent member of an array. | |
Useful for plotting bin counts. | |
''' | |
if base is None: | |
x = np.asarray(x) | |
return (x[1:] + x[:-1])/2. | |
elif base == 'log': | |
return np.exp(mid(np.log(x))) | |
elif base == 'exp': | |
return np.log(mid(np.exp(x))) | |
else: | |
assert base > 0 | |
return np.log(mid(base**x))/np.log(base) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment