[Numpy-svn] r3218 - trunk/numpy/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Sep 26 12:01:30 CDT 2006


Author: stefan
Date: 2006-09-26 12:01:15 -0500 (Tue, 26 Sep 2006)
New Revision: 3218

Modified:
   trunk/numpy/lib/function_base.py
Log:
Sort only once in median.


Modified: trunk/numpy/lib/function_base.py
===================================================================
--- trunk/numpy/lib/function_base.py	2006-09-26 11:20:17 UTC (rev 3217)
+++ trunk/numpy/lib/function_base.py	2006-09-26 17:01:15 UTC (rev 3218)
@@ -1046,11 +1046,10 @@
     """median(m) returns a median of m along the first dimension of m.
     """
     sorted = msort(m)
+    index = int(sorted.shape[0]/2)
     if sorted.shape[0] % 2 == 1:
-        return sorted[int(sorted.shape[0]/2)]
+        return sorted[index]
     else:
-        sorted = msort(m)
-        index = sorted.shape[0]/2
         return (sorted[index-1]+sorted[index])/2.0
 
 def trapz(y, x=None, dx=1.0, axis=-1):



More information about the Numpy-svn mailing list