summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 843e1b85a..fb5dd6fdd 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -542,7 +542,7 @@ def average(a, axis=None, weights=None, returned=False, *,
wgt = np.broadcast_to(wgt, (a.ndim-1)*(1,) + wgt.shape)
wgt = wgt.swapaxes(-1, axis)
- scl = wgt.sum(axis=axis, dtype=result_dtype)
+ scl = wgt.sum(axis=axis, dtype=result_dtype, **keepdims_kw)
if np.any(scl == 0.0):
raise ZeroDivisionError(
"Weights sum to zero, can't be normalized")
@@ -4000,7 +4000,7 @@ def percentile(a,
With 'i' being the floor and 'g' the fractional part of the result.
.. math::
- i + g = (q - alpha) / ( n - alpha - beta + 1 )
+ i + g = q * ( n - alpha - beta + 1 ) + alpha
The different methods then work as follows
@@ -4279,7 +4279,7 @@ def quantile(a,
and alpha and beta are correction constants modifying i and j:
.. math::
- i + g = (q - alpha) / ( n - alpha - beta + 1 )
+ i + g = q * ( n - alpha - beta + 1 ) + alpha
The different methods then work as follows
@@ -5140,10 +5140,14 @@ def delete(arr, obj, axis=None):
single_value = False
_obj = obj
obj = np.asarray(obj)
+ # `size == 0` to allow empty lists similar to indexing, but (as there)
+ # is really too generic:
if obj.size == 0 and not isinstance(_obj, np.ndarray):
obj = obj.astype(intp)
- elif obj.size == 1 and not isinstance(_obj, bool):
- obj = obj.astype(intp).reshape(())
+ elif obj.size == 1 and obj.dtype.kind in "ui":
+ # For a size 1 integer array we can use the single-value path
+ # (most dtypes, except boolean, should just fail later).
+ obj = obj.item()
single_value = True
if single_value: