diff options
author | Antony Lee <anntzer.lee@gmail.com> | 2021-02-04 18:32:54 +0100 |
---|---|---|
committer | Antony Lee <anntzer.lee@gmail.com> | 2021-02-06 12:46:03 +0100 |
commit | 4152443b1d268951401e0be1351eccbddd572e97 (patch) | |
tree | 90c1417bcb2d88baeb50c12d7017d9557d95ced6 /numpy/lib/utils.py | |
parent | 9f12028b9453c17b72b26355fd503e512af96a5d (diff) | |
download | numpy-4152443b1d268951401e0be1351eccbddd572e97.tar.gz |
MAINT: Avoid moveaxis overhead in median.
This change speeds up taking the median of 1001 floats by ~20%, as
measured by
`python -mtimeit -s 'import numpy as np; x = np.random.randn(1001)' -- 'np.median(x)'`
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index f7e176cf3..8f5c6eea3 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1026,8 +1026,7 @@ def _median_nancheck(data, result, axis, out): """ if data.size == 0: return result - data = np.moveaxis(data, axis, -1) - n = np.isnan(data[..., -1]) + n = np.isnan(data.take(-1, axis=axis)) # masked NaN values are ok if np.ma.isMaskedArray(n): n = n.filled(False) |