简体   繁体   中英

Pass an argument to user function for scipy.stats.binned_statistic

I am using

def findT(values, passFraction):
    #...<skipping func body>

def findT90(values):
    return findT(values, 0.9)    

frac90_result = scipy.stats.binned_statistic(m_test, [y_pred], bins=5, range=(0,1),
 statistic=findT90)

but I would like to generalize this so that I can pass any other value in place of 0.9 without having to make a new function. How can I include the passFraction value when calling scipy.stats.binned_statistic

binned_statistic only supports single-argument functions. Therefore, either do what you did, or create a needed function on-the-fly:

binned_statistic(..., statistic=lambda values: findT(values, 0.9))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM