Created
April 15, 2020 22:56
-
-
Save jmmshn/818b3e419b85a1e1a4f905800a7f8061 to your computer and use it in GitHub Desktop.
[Get Filtered Positions] Take an array and a filtering function return all the positions and values for which taht function is true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import product | |
def get_filtered_pos(arr, func): | |
""" | |
Take any ndarray and return the position | |
""" | |
d_ranges = [range(_) for _ in arr.shape] | |
for j in product(*d_ranges): | |
if func(arr[j]): | |
yield j, arr[j] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment