Created
December 20, 2014 21:57
-
-
Save heaven00/0f7f57ad46fa41267c1d to your computer and use it in GitHub Desktop.
A way to check if a value exists in a single row in a numpy array
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
def row_contains(data, query): | |
""" | |
Checks row of the matrix for the given condition | |
and returns a list of rows that satisfies the condition | |
""" | |
condition = np.any(query, axis=1) | |
return np.compress(condition, data, axis=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment