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 | |
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')
-rw-r--r-- | numpy/core/_methods.py | 19 | ||||
-rw-r--r-- | numpy/core/fromnumeric.py | 13 |
2 files changed, 15 insertions, 17 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 diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 35d36d960..e325c5fd1 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -62,9 +62,9 @@ def take(a, indices, axis=None, out=None, mode='raise'): The source array. indices : array_like The indices of the values to extract. - + .. versionadded:: 1.8.0 - + Also allow scalars for indices. axis : int, optional The axis over which to select values. By default, the flattened @@ -2664,8 +2664,7 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False): See Also -------- average : Weighted average - nanmean : Arithmetic mean while ignoring NaNs - var, nanvar + std, var, nanmean, nanstd, nanvar Notes ----- @@ -2752,8 +2751,7 @@ def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): See Also -------- - var, mean - nanmean, nanstd + var, mean, nanmean, nanstd, nanvar numpy.doc.ufuncs : Section "Output arguments" Notes @@ -2856,8 +2854,7 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, See Also -------- - std : Standard deviation - mean : Average + std , mean, nanmean, nanstd, nanvar numpy.doc.ufuncs : Section "Output arguments" Notes |