Apply numpy.where on condition with either list or numpy.array
<p>I discovered that <code>numpy.where</code> behaves differently when applied on a condition such as <code>foo==2</code> when <code>foo</code> is a list or <code>foo</code> is a <code>numpy.array</code></p>

<pre><code>foo = ["a","b","c"]
bar = numpy.array(["a","b","c"])
numpy.where(foo == "a") # Returns array([])
numpy.where(bar == "a") # Returns array([0])
</code></pre>

<p>I want the same command to make this applicable to either list or numpy.array, and I am concerned about how to perform this efficiently. Is the following ok ?</p>

<pre><code>numpy.where(numpy.array(foo, copy=False) == "a") # Returns array([0])
numpy.where(numpy.array(bar, copy=False) == "a") # Returns array([0])
</code></pre>

<p>Result is as expected, but is this the best way to answer my need ? Using each time <code>numpy.array</code> constructor is the best way to ensure object type ?</p>

<p>Thanks !</p>

<p>To me your solution is already the best:</p>

<pre><code>numpy.where(numpy.array(foo, copy=False) == "a")
</code></pre>

<p>It is concise, very clear and totaly efficient thanks to <code>copy=False</code>.</p>

python arrays numpy