I\'d like to create a function that takes a (sorted) list as its argument and outputs a list containing each element\'s corresponding percentile.
For example,
As Kevin said, optimal solution works in O(n log(n)) time. Here is fast version of his code in numpy
, which works almost the same time as stats.rankdata
:
percentiles = numpy.argsort(numpy.argsort(array)) * 100. / (len(array) - 1)
PS. This is one if my favourite tricks in numpy
.