match or vectorized in-type function.

July 13, 2010
2:12 a.m.
I have two vectors of integers of not necessarily the same length. Consider the hypothetical function match (or if you are familiar to R then consider that function). match(v1, v2) => returns a boolean array of length len(v1) indicating whether element i in v1 is in v2. I cannot find this function in numpy. I would assume a variant is there, but not being able to find it I wrote it myself. First, is there such a function? Second, if there is not, is this implementation reasonable? thanks, jim from numpy import * a2 = random.randint(1, 1000, 1000) a1 = random.randint(1, 10000000, 100000) def match(v1, v2): d = dict(zip(v2, range(0, len(v2)))) return array([ d.has_key(x) for x in v1])

5439
Age (days ago)
5439
Last active (days ago)
1 comments
2 participants
participants (2)
-
James Bullard
-
Zachary Pincus