How to make user defined functions for binned_statistic

后端 未结 1 1150
醉话见心
醉话见心 2021-01-03 03:21

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 gen

相关标签:
1条回答
  • 2021-01-03 03:52

    The problem with the function you defined is that it takes no arguments at all! It needs to take a y argument that corresponds to your sample, like this:

    def percentile10(y):
       return(np.percentile(y,10))
    

    You could also use a lambda function for brevity:

    scist.binned_statistic(x, y, statistic=lambda y: np.percentile(y, 10), bins=20,
                           range=[(0, 5)])[0]
    
    0 讨论(0)
提交回复
热议问题