Skip to content

deprecation warning for nonzero(0d_array) not shown #19216

Closed
@rgommers

Description

@rgommers

This is odd, it works as expected for the .nonzero method, but not for the np.nonzero function:

>>> np.__version__
'1.20.2'

>>> x = np.array(3)
>>> x.ndim
0
>>> np.nonzero(x)
(array([0]),)
>>> x.nonzero()
<ipython-input-5-68292516afaf>:1: DeprecationWarning: Calling nonzero on 0d arrays is deprecated, as it behaves surprisingly. Use `atleast_1d(arr).nonzero()` if the old behavior was intended.
  x.nonzero()
(array([0]),)

I haven't looked into why this happens.

The deprecation happened in 1.17.0, see gh-13708.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions