[Numpy-discussion] match or vectorized in-type function.

Zachary Pincus zachary.pincus@yale....
Mon Jul 12 21:32:16 CDT 2010

> match(v1, v2) => returns a boolean array of length len(v1) indicating
> whether element i in v1 is in v2.

You want numpy.in1d (and friends, probably, like numpy.unique and the  
others that are all collected in numpy.lib.arraysetops...)

Definition:       numpy.in1d(ar1, ar2, assume_unique=False)
     Test whether each element of a 1D array is also present in a  
second array.

     Returns a boolean array the same length as `ar1` that is True
     where an element of `ar1` is in `ar2` and False otherwise.

     ar1 : array_like, shape (M,)
         Input array.
     ar2 : array_like
         The values against which to test each value of `ar1`.
     assume_unique : bool, optional
         If True, the input arrays are both assumed to be unique, which
         can speed up the calculation.  Default is False.

     mask : ndarray of bools, shape(M,)
         The values `ar1[mask]` are in `ar2`.

     See Also
     numpy.lib.arraysetops : Module with a number of other functions for
                             performing set operations on arrays.

More information about the NumPy-Discussion mailing list