I have two arrays of points: list1 with list1.shape = [N, 3] and list2 with list2.shape = [M, 3]. Within N, M: the total number of point, (x, y, z) are 3 coordinates in 3D.
Now I want to check if each point of list1 is within a distance r with each point of list2. A nature way to do this is a for loop:
for i in range(N):
for j in range(M):
if (list1[i, 0] - list2[j, 0])**2 + (list1[i, 1] - list2[j, 1])**2 + (list1[i, 2] - list2[j, 2])**2 < r**2:
''' Return 1 if list1[i] is within list2[j] '''
return True
else:
''' Return 0 if list1[i] is not within list2[j] '''
return False
But it's horribly slow. Could I do the more efficient way?