Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def find_rows(a, b):
  2. dt = np.dtype((np.void, a.dtype.itemsize * a.shape[1]))
  3.  
  4. a_view = np.ascontiguousarray(a).view(dt).ravel()
  5. b_view = np.ascontiguousarray(b).view(dt).ravel()
  6.  
  7. sort_b = np.argsort(b_view)
  8. where_in_b = np.searchsorted(b_view, a_view,
  9. sorter=sort_b)
  10. where_in_b = np.take(sort_b, where_in_b)
  11. which_in_a = np.take(b_view, where_in_b) == a_view
  12. where_in_b = where_in_b[which_in_a]
  13. which_in_a = np.nonzero(which_in_a)[0]
  14. return np.column_stack((which_in_a, where_in_b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement