Python equivalent of the R operator "%in%"
If you want to use only numpy
without panads
(like a use case I had) then you can:
import numpy as npx = np.array([1, 2, 3, 10])y = np.array([10, 11, 2])np.isin(y, x)
This is equivalent to:
c(10, 11, 2) %in% c(1, 2, 3, 10)
Note that the last line will work only for numpy >= 1.13.0
, for older versions you'll need to use np.in1d
.