shithub: aubio

Download patch

ref: 0484dc1819cdf9bf8ce7c0916943c36171c35de9
parent: dcc8d90beb1513384145a8f52ae3ea0d839da18f
author: Paul Brossier <piem@altern.org>
date: Tue Feb 28 22:15:54 EST 2006

use a copy for the median
use a copy for the median


--- a/python/aubio/median.py
+++ b/python/aubio/median.py
@@ -27,11 +27,14 @@
 """
 
 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: