Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (45.3k points)

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?

thanks!

1 Answer

0 votes
by (16.8k points)

No, there is no built-in weighted function in numpy for anything, but you can always put something together, try this:

def weight_array(ar, weights):

     zipped = zip(ar, weights)

     weighted = []

     for i in zipped:

         for j in range(i[1]):

             weighted.append(i[0])

     return weighted

np.percentile(weight_array(ar, weights), 25)

Browse Categories

...