<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/819" rel="nofollow">http://projects.scipy.org/numpy/ticket/819</a> on 2008-06-13 by trac user ahaldane, assigned to unknown.</em></p>
<p dir="auto">Hi,</p>
<p dir="auto">I get an unexpected effect from doing .flat on arrays created by c_. In the code below, the values in the variable 'b' seem to get re-ordered during the call to array. Using .flatten() instead works as expected.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from numpy import c_, array
from numpy.random import rand

b = c_[ rand(2,2), rand(2)]

print b
array(b.flat)
print b "><pre class="notranslate"><code class="notranslate">from numpy import c_, array
from numpy.random import rand

b = c_[ rand(2,2), rand(2)]

print b
array(b.flat)
print b 
</code></pre></div>
<p dir="auto">This prints:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[[ 0.8606752   0.11848512  0.95805826]
 [ 0.84665539  0.7989498   0.20762479]]
[[ 0.8606752   0.95805826  0.7989498 ]
 [ 0.11848512  0.84665539  0.20762479]] "><pre class="notranslate"><code class="notranslate">[[ 0.8606752   0.11848512  0.95805826]
 [ 0.84665539  0.7989498   0.20762479]]
[[ 0.8606752   0.95805826  0.7989498 ]
 [ 0.11848512  0.84665539  0.20762479]] 
</code></pre></div>
<p dir="auto">I'm using numpy 1.9.2 (built locally with pip and linked to openblas) and there seems to be a strange bug with memmap. I checked through recent issues/pr and nothing seemed reported (I don't feel like building the master to check this out as I tend to stay on the same version of everything to compare results between themselves). Anyway</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [95]: data.shape
Out[95]: (145, 174, 145, 288)

In [101]: np.mean(data[..., 0:10], axis=-1, keepdims=True).shape
Out[101]: (145, 174, 145)

In [105]: type(data)
Out[105]: numpy.core.memmap.memmap

In [106]: data = np.array(data)

In [107]: np.mean(data[..., 0:10], axis=-1, keepdims=True).shape
Out[107]: (145, 174, 145, 1)"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">95</span>]: <span class="pl-s1">data</span>.<span class="pl-s1">shape</span>
<span class="pl-v">Out</span>[<span class="pl-c1">95</span>]: (<span class="pl-c1">145</span>, <span class="pl-c1">174</span>, <span class="pl-c1">145</span>, <span class="pl-c1">288</span>)

<span class="pl-v">In</span> [<span class="pl-c1">101</span>]: <span class="pl-s1">np</span>.<span class="pl-en">mean</span>(<span class="pl-s1">data</span>[..., <span class="pl-c1">0</span>:<span class="pl-c1">10</span>], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">-</span><span class="pl-c1">1</span>, <span class="pl-s1">keepdims</span><span class="pl-c1">=</span><span class="pl-c1">True</span>).<span class="pl-s1">shape</span>
<span class="pl-v">Out</span>[<span class="pl-c1">101</span>]: (<span class="pl-c1">145</span>, <span class="pl-c1">174</span>, <span class="pl-c1">145</span>)

<span class="pl-v">In</span> [<span class="pl-c1">105</span>]: <span class="pl-en">type</span>(<span class="pl-s1">data</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">105</span>]: <span class="pl-s1">numpy</span>.<span class="pl-s1">core</span>.<span class="pl-s1">memmap</span>.<span class="pl-s1">memmap</span>

<span class="pl-v">In</span> [<span class="pl-c1">106</span>]: <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s1">data</span>)

<span class="pl-v">In</span> [<span class="pl-c1">107</span>]: <span class="pl-s1">np</span>.<span class="pl-en">mean</span>(<span class="pl-s1">data</span>[..., <span class="pl-c1">0</span>:<span class="pl-c1">10</span>], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">-</span><span class="pl-c1">1</span>, <span class="pl-s1">keepdims</span><span class="pl-c1">=</span><span class="pl-c1">True</span>).<span class="pl-s1">shape</span>
<span class="pl-v">Out</span>[<span class="pl-c1">107</span>]: (<span class="pl-c1">145</span>, <span class="pl-c1">174</span>, <span class="pl-c1">145</span>, <span class="pl-c1">1</span>)</pre></div>
<p dir="auto">So the memmap doesn't play well with the keepdims=True, but the numpy array version works as expected.</p>