Skip to content

BUG: count_nonzero(axis=()) is inconsistent #9728

Closed
@eric-wieser

Description

@eric-wieser

A reasonable mental model for count_nonzero is (x != 0).sum(...). But if fails in this case:

>>> x = np.arange(3)
>>> (x != 0).sum(axis=())
array([0, 1, 1])
>>> np.count_nonzero(x != 0, axis=())
2

axis == () should mean (x == 0).astype(int)

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