Skip to content

Instantly share code, notes, and snippets.

@heaven00
Created December 20, 2014 21:57
Show Gist options
  • Save heaven00/0f7f57ad46fa41267c1d to your computer and use it in GitHub Desktop.
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
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