diff options
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 843e1b85a..ca82bb72d 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") @@ -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: |