Skip to content

any() and all() #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tsoernes opened this issue Jun 26, 2018 · 2 comments
Closed

any() and all() #468

tsoernes opened this issue Jun 26, 2018 · 2 comments

Comments

@tsoernes
Copy link

tsoernes commented Jun 26, 2018

In numpy, doing arr.any() returns (short-circuiting) if any element in the array is true. Similarly for all. Do these exist in ndarray (I could not find them), if not, can I request them?

@nilgoyette
Copy link
Collaborator

They don't exist in ndarray, but they exist in Iterator: all and any

You can call iter on your array then use all the methods you want that are defined in the trait Iterator. Something like

if a.iter().any(|&v| v > 4.0) { println!("yeah") }
if a.iter().any(my_func) { ... }

@tsoernes
Copy link
Author

Very good, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants