Weighted percentile using numpy

前端 未结 12 2211
一个人的身影
一个人的身影 2020-12-01 03:28

Is there a way to use the numpy.percentile function to compute weighted percentile? Or is anyone aware of an alternative python function to compute weighted percentile?

12条回答
  •  渐次进展
    2020-12-01 04:21

    I don' know what's Weighted percentile means, but from @Joan Smith's answer, It seems that you just need to repeat every element in ar, you can use numpy.repeat():

    import numpy as np
    np.repeat([1,2,3], [4,5,6])
    

    the result is:

    array([1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3])
    

提交回复
热议问题