diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-06-13 13:44:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-13 13:44:46 +0300 |
commit | 02c8e80d5f65c7870f71c989c425d1bad24bd312 (patch) | |
tree | 690627f8e09fa93962c147eecbe54900473f090c /numpy/core/fromnumeric.py | |
parent | 53c60d4b5152c9dddc584182d96caeb66a3036b4 (diff) | |
parent | dcf9d9628eb50d275a6d42a6ed2cfdd25949ef57 (diff) | |
download | numpy-02c8e80d5f65c7870f71c989c425d1bad24bd312.tar.gz |
Merge pull request #13708 from eric-wieser/deprecate-nonzero
DEP: Deprecate nonzero(0d) in favor of calling atleast_1d explicitly
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index f262f8552..08f17aae4 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1764,17 +1764,17 @@ def nonzero(a): Returns a tuple of arrays, one for each dimension of `a`, containing the indices of the non-zero elements in that dimension. The values in `a` are always tested and returned in - row-major, C-style order. The corresponding non-zero - values can be obtained with:: + row-major, C-style order. - a[nonzero(a)] + To group the indices by element, rather than dimension, use `argwhere`, + which returns a row for each non-zero element. - To group the indices by element, rather than dimension, use:: - - transpose(nonzero(a)) + .. note:: + When called on a zero-d array or scalar, ``nonzero(a)`` is treated + as ``nonzero(atleast1d(a))``. - The result of this is always a 2-D array, with a row for - each non-zero element. + ..deprecated:: 1.17.0 + Use `atleast1d` explicitly if this behavior is deliberate. Parameters ---------- @@ -1795,11 +1795,12 @@ def nonzero(a): Equivalent ndarray method. count_nonzero : Counts the number of non-zero elements in the input array. - + Notes ----- - To obtain the non-zero values, it is recommended to use ``x[x.astype(bool)]`` - which will correctly handle 0-d arrays. + While the nonzero values can be obtained with ``a[nonzero(a)]``, it is + recommended to use ``x[x.astype(bool)]`` or ``x[x != 0]`` instead, which + will correctly handle 0-d arrays. Examples -------- |