Например:
Код: Выделить всё
points = [[1, 1], [2, 2], [5, 5]]
rectangles = [[0, 0, 3, 3], [1, 1, 4, 4], [4, 4, 7, 7]]
result:
(1, 1): [(0, 0, 3, 3), (1, 1, 4, 4)]
(2, 2): [(0, 0, 3, 3), (1, 1, 4, 4)]
(5, 5): [(4, 4, 7, 7)]
Код: Выделить всё
def find_rectangles_containing_points(points, rectangles, chunk_size=1000):
n = points.size(0)
m = rectangles.size(0)
rectangles_containing_points = []
for i in range(0, n, chunk_size):
points_chunk = points[i:i + chunk_size]
points_expanded = points_chunk.unsqueeze(1) # chunk_size x 1 x 2
rectangles_expanded = rectangles.unsqueeze(0) # 1 x m x 4
is_inside = (rectangles_expanded[:, :, :2]
Подробнее здесь: [url]https://stackoverflow.com/questions/77697515/finding-rectangles-enclosing-points[/url]