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>You can use the <code>numpy.in1d</code> function with <code>numpy.where</code>:</p>

<pre><code>import numpy
numpy.where(numpy.in1d(x, [2,3]))
# (array([2, 3]),)
</code></pre>

python numpy