Find numpy vectors in a set quickly
<p>I have a numpy array, for example:</p>

<pre><code>a = np.array([[1,2],
              [3,4],
              [6,4],
              [5,3],
              [3,5]])
</code></pre>

<p>and I also have a set</p>

<pre><code>b = set((1,2),(6,4),(9,9))
</code></pre>

<p>I want to find the index of vectors that exist in set b, here is</p>

<pre><code>[0, 2]
</code></pre>

<p>but I use a for loop to implement this, is there a convinient way to do this job avoiding for loop?
The for loop method I used:</p>

<pre><code>record = []
for i in range(a.shape[0]):
    if (a[i, 0], a[i, 1]) in b:
        record.append(i)
</code></pre>

<p>You can use filter:</p>

<pre><code>In [8]: a = np.array([[1,2],
              [3,4],
              [6,4],
              [5,3],
              [3,5]])

In [9]: b = {(1,2),(6,4)}

In [10]: filter(lambda x: tuple(a[x]) in b, range(len(a)))
Out[10]: [0, 2]
</code></pre>

python numpy set vectorization lookup