3 ms·
I don't think it's the loop implementation. The stuff in the loop should take multiple orders of magnitude more time than the loop itself: for poly in poly
by FreeHugs 4y ago
I don't think it's the loop implementation. The stuff in the loop should take multiple orders of magnitude more time than the loop itself:
for poly in polygon_subset:
if np.linalg.norm(poly.center - point) < max_dist:
close_polygons.append(poly)
- zarzavat 4y agoI don’t know if numpy fixed this, but it used to be that mixing Python numbers with numpy in a tight loop is horribly slow. Try hoisting max_dist out of the loop and replacing it with max_dist_np that converts it to a numpy float once.
- akasakahakada 4y agoSpeaking of this, I once find that for x in numpy.array: is 9X slower than for x in numpy.array.tolist(): in 2021.