<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/648" rel="nofollow">http://projects.scipy.org/numpy/ticket/648</a> on 2008-01-21 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/chanley/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/chanley">@chanley</a>, assigned to unknown.</em></p>
<p dir="auto">The following will cause a bus error on a big endian machine (Solaris 10 Sun in this case):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt; Python 2.5.1 (r251:54863, Jun 29 2007, 15:29:55) [C] on sunos5
&gt; Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt;&gt; import numpy
&gt;&gt;&gt;&gt; o = numpy.ndarray(shape=3,dtype=[('SEGMENT', '|S4'), ('SPEC_FOUND', '|i1')])
&gt;&gt;&gt;&gt; o1 = o.getfield(numpy.dtype('|S4'),0)
&gt;&gt;&gt;&gt; print o1[0]
&gt; UXÐ
&gt;&gt;&gt;&gt; print o1[1]
&gt; 4
&gt;&gt;&gt;&gt; print o1[2]
&gt; NT
&gt;&gt;&gt;&gt; print o1
&gt; Bus error (core dumped)"><pre class="notranslate"><code class="notranslate">&gt; Python 2.5.1 (r251:54863, Jun 29 2007, 15:29:55) [C] on sunos5
&gt; Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt;&gt; import numpy
&gt;&gt;&gt;&gt; o = numpy.ndarray(shape=3,dtype=[('SEGMENT', '|S4'), ('SPEC_FOUND', '|i1')])
&gt;&gt;&gt;&gt; o1 = o.getfield(numpy.dtype('|S4'),0)
&gt;&gt;&gt;&gt; print o1[0]
&gt; UXÐ
&gt;&gt;&gt;&gt; print o1[1]
&gt; 4
&gt;&gt;&gt;&gt; print o1[2]
&gt; NT
&gt;&gt;&gt;&gt; print o1
&gt; Bus error (core dumped)
</code></pre></div>
<p dir="auto">There are no issues on Linux or Mac OS X Intel based systems.</p>
<p dir="auto">This example was done on the latest svn version of numpy (r1.0.5.dev47360).</p>
<p dir="auto">np.percentile claims to function with the <code class="notranslate">q</code> argument (the percentiles to calculate) being either a scalar or an array_like. However, the initial lines of code do:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="if q == 0:
    return a.min(axis=axis, out=out)
elif q == 100:
    return a.max(axis=axis, out=out)"><pre class="notranslate"><code class="notranslate">if q == 0:
    return a.min(axis=axis, out=out)
elif q == 100:
    return a.max(axis=axis, out=out)
</code></pre></div>
<p dir="auto">which of course breaks with a "truth value of array undefined" exception if <code class="notranslate">q</code> is in fact an ndarray.</p>
<p dir="auto"><code class="notranslate">q</code> isn't converted to an array before usage, so if it's passed as a list value, these checks don't cause an exception, but only because of the sketchiness of Python's built-in equality testing. I've gotten a report of a crash in the <code class="notranslate">_compute_qth_percentile</code> function that seems to be due to the lack of coercion.</p>