summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorPieter Eendebak <pieter.eendebak@gmail.com>2022-07-18 21:54:00 +0200
committerPieter Eendebak <pieter.eendebak@gmail.com>2022-08-10 23:46:37 +0200
commit25d5e385ec537f911702f905ca050815e320865a (patch)
treeed42a135529a2a086ffcd7013fa9bb56f6b380a8 /numpy/lib/function_base.py
parent86a368f53ba15a610be4c6cb3a173446aef3aa80 (diff)
downloadnumpy-25d5e385ec537f911702f905ca050815e320865a.tar.gz
BUG: fix np.average for Fraction elements
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index fb5dd6fdd..960285f7d 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -516,7 +516,8 @@ def average(a, axis=None, weights=None, returned=False, *,
if weights is None:
avg = a.mean(axis, **keepdims_kw)
- scl = avg.dtype.type(a.size/avg.size)
+ avg_as_array = np.asanyarray(avg)
+ scl = avg_as_array.dtype.type(a.size/avg_as_array.size)
else:
wgt = np.asanyarray(weights)
@@ -547,12 +548,12 @@ def average(a, axis=None, weights=None, returned=False, *,
raise ZeroDivisionError(
"Weights sum to zero, can't be normalized")
- avg = np.multiply(a, wgt,
+ avg = avg_as_array = np.multiply(a, wgt,
dtype=result_dtype).sum(axis, **keepdims_kw) / scl
if returned:
- if scl.shape != avg.shape:
- scl = np.broadcast_to(scl, avg.shape).copy()
+ if scl.shape != avg_as_array.shape:
+ scl = np.broadcast_to(scl, avg_as_array.shape).copy()
return avg, scl
else:
return avg