I am using scipy stats package to take statistics along the an axis, but I am having trouble taking the percentile statistic using binned_statistic
. I have generalized the code below, where I am trying taking the 10th percentile of a dataset with x, y values within a series of x bins, and it fails.
I can of course do function options, like median, and even the numpy standard deviation using np.std
. However, I cannot figure out how to use np.percentile
because it requires 2 arguments (e.g. np.percentile(y, 10)
), but then it gives me a ValueError: statistic not understood
error.
import numpy as np import scipy.stats as scist y_median = scist.binned_statistic(x,y,statistic='median',bins=20,range=[(0,5)])[0] y_std = scist.binned_statistic(x,y,statistic=np.std,bins=20,range=[(0,5)])[0] y_10 = scist.binned_statistic(x,y,statistic=np.percentile(10),bins=20,range=[(0,5)])[0] print y_median print y_std print y_10
I am at a loss and have even played around with user defined functions like this, but with no luck:
def percentile10(): return(np.percentile(y,10))
Any help, is greatly appreciated.
Thanks.