From 70d8dc82da3b5de412356cb148c0d35b8d062ae7 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Fri, 15 Nov 2019 10:15:11 +0100 Subject: [PATCH] enforce integer division in Python 2: 1/2=0 in Python 3: 1/2 = 0.5 --- modules/base/pymod/stutil.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/base/pymod/stutil.py b/modules/base/pymod/stutil.py index 506675f12..705b56f8d 100644 --- a/modules/base/pymod/stutil.py +++ b/modules/base/pymod/stutil.py @@ -15,10 +15,11 @@ def Median(xs): if len(xs)==0: raise RuntimeError("Can't calculate median of empty sequence") sorted_xs=sorted(xs) + central_idx = int((len(xs)-1)/2) if (len(xs) % 2)==0: - return (sorted_xs[(len(xs)-1)/2]+sorted_xs[(len(xs)-1)/2+1])/2.0 + return (sorted_xs[central_idx]+sorted_xs[central_idx+1])/2.0 else: - return sorted_xs[(len(xs)-1)/2] + return sorted_xs[central_idx] def StdDev(xs): """ -- GitLab