What purpose does [0] serve in numpy.where(y_euler<0.0)[0]
<p>Also what is the difference between this:</p>

<pre><code>idx_negative_euler = numpy.where(y_euler&lt;0.0)[0]
</code></pre>

<p>and this:</p>

<pre><code>idx_negative_euler = numpy.where(y_euler&lt;0.0)[0][0]
</code></pre>

<p>I realize that this returns an array of indices where the array <code>y_euler</code> is negative, however I simply can't figure out what the <code>[0]</code> or the <code>[0][0]</code> at the end of the line is supposed to do.</p>

<p>I couldn't find any documentation regarding this (I'm not even sure what to search for). I've already looked into the <code>numpy.where</code> documentation but that didn't help.</p>

<p><code>[0]</code> means "get the first item of the sequence."  For example if you had this list:</p>

<pre><code>x = [5, 7, 9]
</code></pre>

<p>Then <code>x[0]</code> would be the first item of that sequence: 5.</p>

<p><code>numpy.where()</code> returns a sequence.  Putting <code>[0]</code> on the end of that expression gets the first item in that sequence.</p>

<p><code>[0][0]</code> means "get the first item in the sequence (which is itself also a sequence), and then get the first item in <em>that</em> sequence".  So if <code>numpy.where()</code> returned a list of lists, <code>[0][0]</code> would get the first item in the first list.</p>

python arrays numpy