Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def get_matches(x, y, r):
  4. sorted_idx = np.argsort(y)
  5.  
  6. y = y[sorted_idx]
  7. matches = []
  8. for i in range(x.shape[0]):
  9. left = np.searchsorted(y, x[i] - r, side='left')
  10. right = np.searchsorted(y, x[i] + r, side='right')
  11. matches.append(list(range(left, right)))
  12. return matches
  13.  
  14.  
  15. if __name__ == '__main__':
  16. x = np.array([1, 2, 3])
  17. y = np.array([3, 4, 5])
  18. r = 2
  19. matches = get_matches(x, y, r)
  20. print(matches)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement