diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-06-03 09:31:38 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-03 09:31:38 -0600 |
commit | 48b0374b8cb2e06a1bc620a9dcaa35c2d92753f2 (patch) | |
tree | b02ce41cd466d1fba0d5918904ffbd3b128f1444 /numpy | |
parent | e5e2cf89d01d7b09631977482b11df79e8131c6d (diff) | |
parent | cbaa809820656bf39f4ec78a9bec1426239ce440 (diff) | |
download | numpy-48b0374b8cb2e06a1bc620a9dcaa35c2d92753f2.tar.gz |
Merge pull request #9214 from eric-wieser/no-one-arg-where
MAINT: Don't internally use the one-argument where
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/numeric.py | 2 | ||||
-rw-r--r-- | numpy/doc/indexing.py | 2 | ||||
-rw-r--r-- | numpy/doc/misc.py | 3 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 2 | ||||
-rw-r--r-- | numpy/lib/nanfunctions.py | 4 | ||||
-rw-r--r-- | numpy/lib/twodim_base.py | 7 | ||||
-rw-r--r-- | numpy/polynomial/polyutils.py | 2 |
7 files changed, 12 insertions, 10 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 9073ca5ff..83f2ce838 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -838,7 +838,7 @@ def argwhere(a): ``np.argwhere(a)`` is the same as ``np.transpose(np.nonzero(a))``. The output of ``argwhere`` is not suitable for indexing arrays. - For this purpose use ``where(a)`` instead. + For this purpose use ``nonzero(a)`` instead. Examples -------- diff --git a/numpy/doc/indexing.py b/numpy/doc/indexing.py index 39b2c73ed..b286a904d 100644 --- a/numpy/doc/indexing.py +++ b/numpy/doc/indexing.py @@ -422,7 +422,7 @@ object: :: [37, 40, 43], [46, 49, 52]]) -For this reason it is possible to use the output from the np.where() +For this reason it is possible to use the output from the np.nonzero() function directly as an index since it always returns a tuple of index arrays. diff --git a/numpy/doc/misc.py b/numpy/doc/misc.py index 37ebca572..5d6708a0d 100644 --- a/numpy/doc/misc.py +++ b/numpy/doc/misc.py @@ -14,7 +14,8 @@ original value was) Note: cannot use equality to test NaNs. E.g.: :: >>> myarr = np.array([1., 0., np.nan, 3.]) - >>> np.where(myarr == np.nan) + >>> np.nonzero(myarr == np.nan) + (array([], dtype=int64),) >>> np.nan == np.nan # is always False! Use special numpy functions instead. False >>> myarr[myarr == np.nan] = 0. # doesn't work diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 1e6223e7c..a127c366b 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -974,7 +974,7 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): on_edge = (around(sample[:, i], decimal) == around(edges[i][-1], decimal)) # Shift these points one bin to the left. - Ncount[i][where(on_edge & not_smaller_than_edge)[0]] -= 1 + Ncount[i][nonzero(on_edge & not_smaller_than_edge)[0]] -= 1 # Flattened histogram matrix (1D) # Reshape is used so that overlarge arrays diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index 6bd949b34..97bd33492 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -837,7 +837,7 @@ def _nanmedian1d(arr1d, overwrite_input=False): See nanmedian for parameter usage """ c = np.isnan(arr1d) - s = np.where(c)[0] + s = np.nonzero(c)[0] if s.size == arr1d.size: warnings.warn("All-NaN slice encountered", RuntimeWarning, stacklevel=3) return np.nan @@ -1161,7 +1161,7 @@ def _nanpercentile1d(arr1d, q, overwrite_input=False, interpolation='linear'): See nanpercentile for parameter usage """ c = np.isnan(arr1d) - s = np.where(c)[0] + s = np.nonzero(c)[0] if s.size == arr1d.size: warnings.warn("All-NaN slice encountered", RuntimeWarning, stacklevel=3) if q.ndim == 0: diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py index 28ebb8cbd..a6259219a 100644 --- a/numpy/lib/twodim_base.py +++ b/numpy/lib/twodim_base.py @@ -6,6 +6,7 @@ from __future__ import division, absolute_import, print_function from numpy.core.numeric import ( absolute, asanyarray, arange, zeros, greater_equal, multiply, ones, asarray, where, int8, int16, int32, int64, empty, promote_types, diagonal, + nonzero ) from numpy.core import iinfo, transpose @@ -717,7 +718,7 @@ def mask_indices(n, mask_func, k=0): """ m = ones((n, n), int) a = mask_func(m, k) - return where(a != 0) + return nonzero(a != 0) def tril_indices(n, k=0, m=None): @@ -797,7 +798,7 @@ def tril_indices(n, k=0, m=None): [-10, -10, -10, -10]]) """ - return where(tri(n, m, k=k, dtype=bool)) + return nonzero(tri(n, m, k=k, dtype=bool)) def tril_indices_from(arr, k=0): @@ -907,7 +908,7 @@ def triu_indices(n, k=0, m=None): [ 12, 13, 14, -1]]) """ - return where(~tri(n, m, k=k-1, dtype=bool)) + return nonzero(~tri(n, m, k=k-1, dtype=bool)) def triu_indices_from(arr, k=0): diff --git a/numpy/polynomial/polyutils.py b/numpy/polynomial/polyutils.py index 59f130a60..e2dba1a55 100644 --- a/numpy/polynomial/polyutils.py +++ b/numpy/polynomial/polyutils.py @@ -236,7 +236,7 @@ def trimcoef(c, tol=0): raise ValueError("tol must be non-negative") [c] = as_series([c]) - [ind] = np.where(np.abs(c) > tol) + [ind] = np.nonzero(np.abs(c) > tol) if len(ind) == 0: return c[:1]*0 else: |