diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2020-05-17 23:13:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 23:13:24 +0100 |
commit | a6b4b2bdd6baf2afde27284097426e93912452e9 (patch) | |
tree | f214724b5295a592e919360c2357153f07503e7e /numpy/lib/function_base.py | |
parent | 4f88a0267a3a4992aacde45df7719fdef713bedc (diff) | |
parent | 49a84f6fd548c0d01d5dbd6ee286cdaa49fd6209 (diff) | |
download | numpy-a6b4b2bdd6baf2afde27284097426e93912452e9.tar.gz |
Merge pull request #16274 from eric-wieser/extract-lerp
MAINT: cleanups to quantile
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index dea01d12d..2d1adc362 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3943,42 +3943,29 @@ def _quantile_ureduce_func(a, q, axis=None, out=None, overwrite_input=False, if np.issubdtype(a.dtype, np.inexact): indices_above = concatenate((indices_above, [-1])) - weights_above = indices - indices_below - weights_below = 1 - weights_above - - weights_shape = [1, ] * ap.ndim - weights_shape[axis] = len(indices) - weights_below.shape = weights_shape - weights_above.shape = weights_shape - ap.partition(concatenate((indices_below, indices_above)), axis=axis) # ensure axis with q-th is first ap = np.moveaxis(ap, axis, 0) - weights_below = np.moveaxis(weights_below, axis, 0) - weights_above = np.moveaxis(weights_above, axis, 0) axis = 0 + weights_shape = [1] * ap.ndim + weights_shape[axis] = len(indices) + weights_above = (indices - indices_below).reshape(weights_shape) + # Check if the array contains any nan's if np.issubdtype(a.dtype, np.inexact): indices_above = indices_above[:-1] n = np.isnan(ap[-1:, ...]) - x1 = take(ap, indices_below, axis=axis) * weights_below + x1 = take(ap, indices_below, axis=axis) * (1 - weights_above) x2 = take(ap, indices_above, axis=axis) * weights_above - # ensure axis with q-th is first - x1 = np.moveaxis(x1, axis, 0) - x2 = np.moveaxis(x2, axis, 0) - if zerod: x1 = x1.squeeze(0) x2 = x2.squeeze(0) - if out is not None: - r = add(x1, x2, out=out) - else: - r = add(x1, x2) + r = add(x1, x2, out=out) if np.any(n): if zerod: |