> Seems reasonable. I don't know if it is faster, but NumPy is all about 
> vectorization.
Surely speed needs to fit into equation somehow?

Another point to consider. Is function `in1d` able to achieve everything that 
`intersect1d` does?

For 2 arrays of length 1600.
def intersect1d_via_in1d(x, y):
    return np.unique(r1[np.in1d(x, y)])

%timeit np.intersect1d(r1, r2)          # 927 µs ± 10.2
%timeit intersect1d_via_in1d(r1, r2)    # 163 µs ± 1.73
Retrieving indices and other outputs that `intersect1d` provides also seems 
trivial.

If it is faster and doesn’t consume more memory, then maybe it is more 
worthwhile re-using it in `intersect1d`?

Regards,
DG
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to