def unq_searchsorted(A, B):
    unqA, idx1 = np.unique(A, return_inverse=True)
unqB, idx2 = np.unique(B, return_inverse=True)
mask1 = np.searchsorted(unqB, unqA, 'right') - np.searchsorted(unqB, unqA,
    'left') == 1
mask2 = np.searchsorted(unqA, unqB, 'right') - np.searchsorted(unqA, unqB,
    'left') == 1
return mask1[idx1], mask2[idx2]
Find indices of common values in two arrays