From: Paul Brossier Date: Wed, 1 Mar 2006 03:15:54 +0000 (+0000) Subject: use a copy for the median X-Git-Tag: bzr2git~751 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0484dc1819cdf9bf8ce7c0916943c36171c35de9;p=aubio.git use a copy for the median use a copy for the median --- diff --git a/python/aubio/median.py b/python/aubio/median.py index e0f9eea0..b039725b 100644 --- a/python/aubio/median.py +++ b/python/aubio/median.py @@ -27,11 +27,14 @@ inspired from http://www.ics.uci.edu/~eppstein/161/python/peters-selection.py """ def short_find(a, rank): - a.sort() - return a[rank - 1] + """ find the rank-th value in sorted a """ + # copy to b before sorting + b = a[:] + b.sort() + return b[rank - 1] -# Find the rank'th-smallest value in a, in worst-case linear time. def percental(a, rank): + """ Find the rank'th-smallest value in a, in worst-case linear time. """ n = len(a) assert 1 <= rank <= n if n <= 7: