numpy.where for 2+ specific values
<p>Can the numpy.where function be used for more than one specific value?</p>

<p>I can specify a specific value:</p>

<pre><code>&gt;&gt;&gt; x = numpy.arange(5)
&gt;&gt;&gt; numpy.where(x == 2)[0][0]
2
</code></pre>

<p>But I would like to do something like the following. It gives an error of course.</p>

<pre><code>&gt;&gt;&gt; numpy.where(x in [3,4])[0][0]
[3,4]
</code></pre>

<p>Is there a way to do this without iterating through the list and combining the resulting arrays?</p>

<p><strong>EDIT:</strong> I also have a lists of lists of unknown lengths and unknown values so I cannot easily form the parameters of np.where() to search for multiple items. It would be much easier to pass a list.</p>

<p>If you only need to check for a few values you can:</p>

<pre><code>import numpy as np
x = np.arange(4)

ret_arr = np.where([x == 1, x == 2, x == 4, x == 0])[1]
print "Ret arr = ",ret_arr
</code></pre>

<p>Output:</p>

<pre><code>Ret arr =  [1 2 0]
</code></pre>

python numpy