Skip to content

ENH: Should np.nonzero throw exception on 0D input? #26238

@mtsokol

Description

@mtsokol

Proposed new feature or change:

The Array API standard says that np.nonzero should throw an exception for 0D input.

Currently, np.nonzero implicitly makes 0D input a 1D (with atleast_1d), no warning is raised a warning is raised. In its docstring it says:

       .. deprecated:: 1.17.0

          Use `atleast_1d` explicitly if this behavior is deliberate.

Also np.array(1).nonzero() gives a deprecation warning:

DeprecationWarning: Calling nonzero on 0d arrays is deprecated, as it behaves surprisingly. Use `atleast_1d(arr).nonzero()` if the old behavior was intended.

Do we want to throw an exception on 0D input for both cases for Array API compatibility?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions