<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/976" rel="nofollow">http://projects.scipy.org/scipy/ticket/976</a> on 2009-07-16 by trac user senyai, assigned to unknown.</em></p>
<p dir="auto">I've got python 2.5.4, scipy 0.7.1 under windows XP 32 with 2G ram. I get crash when running [http://www.arseniy.net/files/scipy_bug.py]</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/905" rel="nofollow">http://projects.scipy.org/scipy/ticket/905</a> on 2009-03-31 by trac user parejkoj, assigned to unknown.</em></p>
<p dir="auto">I'm trying to run scipy.stats.mode (in scipy.stats.stats) on a 2-d ndarray, but it takes an extremely long time.  The data is an image (astronomical data), with:</p>
<p dir="auto">data.shape = (227,3104)<br>
data.dtype = ('float32')</p>
<p dir="auto">A quick-and-dirty mode function like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def mode(data):
    counts = {}
    for x in data.flatten():
    counts[x] = counts.get(x,0) + 1
    maxcount = max(counts.values())
    modelist = []
    for x in counts:
    if counts[x] == maxcount:
        modelist.append(x)
    return modelist,maxcount
#..."><pre class="notranslate"><code class="notranslate">def mode(data):
    counts = {}
    for x in data.flatten():
    counts[x] = counts.get(x,0) + 1
    maxcount = max(counts.values())
    modelist = []
    for x in counts:
    if counts[x] == maxcount:
        modelist.append(x)
    return modelist,maxcount
#...
</code></pre></div>
<p dir="auto">takes only a second or so to run, while stats.mode(data) or stats.mode(data.flatten()) takes ~20 minutes, no matter how I set the axis parameter.  Am I missing something, or shouldn't it be significantly faster?</p>
<p dir="auto">I'm using scipy 0.6.0 from Fink on Mac OS X Leopard with python2.5, but there appear to be no changes to the mode function between 0.6.0 and the current svn.</p>