8000 any/all functions do not work with generators · Issue #6555 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
any/all functions do not work with generators #6555
Open
@frobnitzem

Description

@frobnitzem

Numpy's any() (and all()) functions should work with generator expressions to be consistent with basic python. I spent several hours trying to debug a case of this, which would work if I used a list, but not if I used a generator expression -- only to discover that it was because numpy's all() function was being used instead of the usual python one that works identically with both generators and lists.

lst = [0,1,2]

print any(i < 0 for i in lst) # False
from numpy import any
print any([i < 0 for i in lst]) # False
print any(i < 0 for i in lst) # <generator object <genexpr> at 0x1006bd500>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0