diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-07-13 20:54:43 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-08-12 22:33:56 -0600 |
commit | f16b12e87667a85ab0dd6e26ddd4083117459fa6 (patch) | |
tree | 563367b92366a482fd4a0fc04a6ea0c79b127670 /numpy/core/_methods.py | |
parent | 1b6b8719735ca3e98a0a0c3f492f16ff00ba1aa9 (diff) | |
download | numpy-f16b12e87667a85ab0dd6e26ddd4083117459fa6.tar.gz |
BUG: Make mean, sum, var, std methods return correct scalar type.
The return type could differ depending on whether or not the value
was a scalar.
Diffstat (limited to 'numpy/core/_methods.py')
-rw-r--r-- | numpy/core/_methods.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index 6312d35cf..ccf02ce36 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -57,10 +57,10 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False): rcount = _count_reduce_items(arr, axis) if isinstance(ret, mu.ndarray): - ret = um.true_divide(ret, rcount, - out=ret, casting='unsafe', subok=False) + ret = um.true_divide( + ret, rcount, out=ret, casting='unsafe', subok=False) else: - ret = ret / rcount + ret = ret.dtype.type(ret / rcount) return ret @@ -76,10 +76,10 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, rcount = _count_reduce_items(arr, axis) if isinstance(arrmean, mu.ndarray): - arrmean = um.true_divide(arrmean, rcount, - out=arrmean, casting='unsafe', subok=False) + arrmean = um.true_divide( + arrmean, rcount, out=arrmean, casting='unsafe', subok=False) else: - arrmean = arrmean / rcount + arrmean = arrmean.dtype.type(arrmean / rcount) # arr - arrmean x = arr - arrmean @@ -98,10 +98,10 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, rcount = rcount.squeeze(axis=axis) rcount -= ddof if isinstance(ret, mu.ndarray): - ret = um.true_divide(ret, rcount, - out=ret, casting='unsafe', subok=False) + ret = um.true_divide( + ret, rcount, out=ret, casting='unsafe', subok=False) else: - ret = ret / rcount + ret = ret.dtype.type(ret / rcount) return ret @@ -112,7 +112,7 @@ def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): if isinstance(ret, mu.ndarray): ret = um.sqrt(ret, out=ret) else: - ret = um.sqrt(ret) + ret = ret.dtype.type(um.sqrt(ret)) return ret |