diff options
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 844c069c0..fbe41442b 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3541,7 +3541,7 @@ def _percentile(a, q, axis=None, out=None, elif interpolation == 'higher': indices = ceil(indices).astype(intp) elif interpolation == 'midpoint': - indices = floor(indices) + 0.5 + indices = 0.5 * (floor(indices) + ceil(indices)) elif interpolation == 'nearest': indices = around(indices).astype(intp) elif interpolation == 'linear': diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index d6a838f3a..56466c1ea 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2055,7 +2055,7 @@ def compare_results(res, desired): assert_array_equal(res[i], desired[i]) -class TestScoreatpercentile(TestCase): +class TestPercentile(TestCase): def test_basic(self): x = np.arange(8) * 0.5 @@ -2104,6 +2104,10 @@ class TestScoreatpercentile(TestCase): def test_midpoint(self): assert_equal(np.percentile(range(10), 51, interpolation='midpoint'), 4.5) + assert_equal(np.percentile(range(11), 51, + interpolation='midpoint'), 5.5) + assert_equal(np.percentile(range(11), 50, + interpolation='midpoint'), 5) def test_nearest(self): assert_equal(np.percentile(range(10), 51, |