[Numpy-discussion] algorithm for faster median calculation ?

Sturla Molden sturla@molden...
Tue Jan 15 15:18:19 CST 2013



On 15.01.2013 20:50, Sturla Molden wrote:
> You might want to look at this first:
>
> https://github.com/numpy/numpy/issues/1811
>
> Yes it is possible to compute the median faster by doing quickselect
> instead of quicksort. Best case O(n) for quickselect, O(n log n) for
> quicksort. But adding selection and partial sorting to NumPy is a bigger
> issue than just computing medians and percentiles faster.


Anyway, here is the code, a bit updated.

I prefer quickselect with a better pivot though.

Sturla
-------------- next part --------------
A non-text attachment was scrubbed...
Name: median.py
Type: text/x-python
Size: 5604 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130115/72c1d727/attachment-0001.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: quickselect.pyx
Type: /
Size: 3346 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130115/72c1d727/attachment-0001.bin 


More information about the NumPy-Discussion mailing list