Skip to content

Instantly share code, notes, and snippets.

@straussmaximilian
Created September 21, 2019 12:52
Show Gist options
  • Save straussmaximilian/802e00828b5dc66d11dac2062f8d5e78 to your computer and use it in GitHub Desktop.
Save straussmaximilian/802e00828b5dc66d11dac2062f8d5e78 to your computer and use it in GitHub Desktop.
def python_loop(random_list):
"""
Takes a list of tuples 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.
"""
filtered_list = []
for i in range(len(random_list)):
if ((random_list[i][0] >= 0.2)
and (random_list[i][1] >= 0.4)
and (random_list[i][0] <= 0.4)
and (random_list[i][1] <= 0.6)):
filtered_list.append(random_list[i])
return filtered_list
# Convert the numpy array to a list of tuples
python_list = list(map(tuple, array))
print('Python loop:\t', end='')
%timeit python_loop(python_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment