From 61fbe0e45c5e22054190b6973d7f23c1f95434e6 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 26 Sep 2006 17:01:15 +0000 Subject: Sort only once in median. --- numpy/lib/function_base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index f13736f2a..4478a332f 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1046,11 +1046,10 @@ def median(m): """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): -- cgit v1.2.1