diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-01-24 16:07:52 +0100 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-01-24 16:14:24 +0100 |
commit | 9ae84854d9c48a751e57c5cd0e9636678a6d2359 (patch) | |
tree | b159857c74b977a84b05c184e5c8e9f734215c2e | |
parent | 5da51cba3367432cdb6ae3ee3834509c306b737d (diff) | |
download | numpy-9ae84854d9c48a751e57c5cd0e9636678a6d2359.tar.gz |
BUG: fix mean for float 16 non-array inputs
-rw-r--r-- | numpy/core/_methods.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index abfd0a3cc..c05316d18 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -72,10 +72,10 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False): ret = um.true_divide( ret, rcount, out=ret, casting='unsafe', subok=False) if is_float16_result and out is None: - ret = a.dtype.type(ret) + ret = arr.dtype.type(ret) elif hasattr(ret, 'dtype'): if is_float16_result: - ret = a.dtype.type(ret / rcount) + ret = arr.dtype.type(ret / rcount) else: ret = ret.dtype.type(ret / rcount) else: diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index b21e193b9..6bd451498 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -4380,6 +4380,12 @@ class TestStats(TestCase): self.omat = np.array([Decimal(repr(r)) for r in self.rmat.flat]) self.omat = self.omat.reshape(4, 5) + def test_python_type(self): + for x in (np.float16(1.), 1, 1., 1+0j): + assert_equal(np.mean([x]), 1.) + assert_equal(np.std([x]), 0.) + assert_equal(np.var([x]), 0.) + def test_keepdims(self): mat = np.eye(3) for f in self.funcs: |