diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-06-21 10:28:41 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-08-12 22:33:55 -0600 |
commit | 1b6b8719735ca3e98a0a0c3f492f16ff00ba1aa9 (patch) | |
tree | 1042eabf7cc7335c3813a5bdc537b79924f31bbd /numpy/core/_methods.py | |
parent | fcb0fef5c673ed0a5442b18bcd8c391907b4f9a7 (diff) | |
download | numpy-1b6b8719735ca3e98a0a0c3f492f16ff00ba1aa9.tar.gz |
MAINT: Clean up core/_methods.py and core/fromnumeric.py
Use issubclass instead of issubdtype.
Add some blank lines.
Remove trailing whitespace.
Remove uneeded float casts since true_divide is default.
Clean up documentation a bit.
Diffstat (limited to 'numpy/core/_methods.py')
-rw-r--r-- | numpy/core/_methods.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index 51731b9c2..6312d35cf 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -7,7 +7,7 @@ from __future__ import division, absolute_import, print_function from numpy.core import multiarray as mu from numpy.core import umath as um -from numpy.core.numeric import asanyarray, isnan, issubdtype +from numpy.core.numeric import asanyarray from numpy.core import numerictypes as nt def _amax(a, axis=None, out=None, keepdims=False): @@ -48,19 +48,20 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False): arr = asanyarray(a) # Cast bool, unsigned int, and int to float64 - if dtype is None and (issubdtype(arr.dtype, nt.integer) or - issubdtype(arr.dtype, nt.bool_)): + if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)): ret = um.add.reduce(arr, axis=axis, dtype='f8', out=out, keepdims=keepdims) else: ret = um.add.reduce(arr, axis=axis, dtype=dtype, out=out, keepdims=keepdims) + rcount = _count_reduce_items(arr, axis) if isinstance(ret, mu.ndarray): ret = um.true_divide(ret, rcount, out=ret, casting='unsafe', subok=False) else: - ret = ret / float(rcount) + ret = ret / rcount + return ret def _var(a, axis=None, dtype=None, out=None, ddof=0, @@ -68,23 +69,23 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, arr = asanyarray(a) # First compute the mean, saving 'rcount' for reuse later - if dtype is None and (issubdtype(arr.dtype, nt.integer) or - issubdtype(arr.dtype, nt.bool_)): + if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)): arrmean = um.add.reduce(arr, axis=axis, dtype='f8', keepdims=True) else: arrmean = um.add.reduce(arr, axis=axis, dtype=dtype, keepdims=True) + rcount = _count_reduce_items(arr, axis) if isinstance(arrmean, mu.ndarray): arrmean = um.true_divide(arrmean, rcount, out=arrmean, casting='unsafe', subok=False) else: - arrmean = arrmean / float(rcount) + arrmean = arrmean / rcount # arr - arrmean x = arr - arrmean # (arr - arrmean) ** 2 - if issubdtype(arr.dtype, nt.complex_): + if issubclass(arr.dtype.type, nt.complexfloating): x = um.multiply(x, um.conjugate(x), out=x).real else: x = um.multiply(x, x, out=x) @@ -100,7 +101,7 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, ret = um.true_divide(ret, rcount, out=ret, casting='unsafe', subok=False) else: - ret = ret / float(rcount) + ret = ret / rcount return ret |