Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def get_matches(x, y, r):
- sorted_idx = np.argsort(y)
- y = y[sorted_idx]
- matches = []
- for i in range(x.shape[0]):
- left = np.searchsorted(y, x[i] - r, side='left')
- right = np.searchsorted(y, x[i] + r, side='right')
- matches.append(list(range(left, right)))
- return matches
- if __name__ == '__main__':
- x = np.array([1, 2, 3])
- y = np.array([3, 4, 5])
- r = 2
- matches = get_matches(x, y, r)
- print(matches)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement