Skip to content

Instantly share code, notes, and snippets.

@straussmaximilian
Created September 21, 2019 12:56
Show Gist options
  • Save straussmaximilian/654928ee8ca4883f8e51030a6d0f064a to your computer and use it in GitHub Desktop.
Save straussmaximilian/654928ee8ca4883f8e51030a6d0f064a to your computer and use it in GitHub Desktop.
def boolean_index(array):
"""
Takes a numpy array and isolates all points that are within [0.2,0.4] for
the first dimension and between [0.4,0.6] for
the second dimension by creating a boolean index.
"""
index = (array[:, 0] >= 0.2) & (array[:, 1] >= 0.4) & (array[:, 0] <= 0.4) & (array[:, 1] <= 0.6)
return array[index]
print('Boolean index:\t', end='')
%timeit boolean_index(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment