summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-10-27 20:30:19 +0100
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-10-27 20:30:19 +0100
commit7be18edfaae4d0ba6a888160d1cc57c453b568f2 (patch)
tree85c0f49236a2158d9679fdd8ee5b0fa8db4ad5d3 /numpy/lib/function_base.py
parent16575443239fa84615fc795692a79ef27f25c216 (diff)
parent3d5f499fd6807186baf669eec491034766caab34 (diff)
downloadnumpy-7be18edfaae4d0ba6a888160d1cc57c453b568f2.tar.gz
Merge pull request #5214 from mkowoods/np.average
Update to average calculation
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 35195338f..36ce94bad 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -515,8 +515,7 @@ def average(a, axis=None, weights=None, returned=False):
scl = avg.dtype.type(a.size/avg.size)
else:
a = a + 0.0
- wgt = np.array(weights, dtype=a.dtype, copy=0)
-
+ wgt = np.asarray(weights)
# Sanity checks
if a.shape != wgt.shape:
if axis is None:
@@ -533,7 +532,7 @@ def average(a, axis=None, weights=None, returned=False):
# setup wgt to broadcast along axis
wgt = np.array(wgt, copy=0, ndmin=a.ndim).swapaxes(-1, axis)
- scl = wgt.sum(axis=axis)
+ scl = wgt.sum(axis=axis, dtype=np.result_type(a.dtype, wgt.dtype))
if (scl == 0.0).any():
raise ZeroDivisionError(
"Weights sum to zero, can't be normalized")