Print elements of ndarray in their storage order
<p>To check whether my assumptions on memory layout are correct, I'd sometimes like to print elements of an <code>ndarray</code> exactly in the storage order in memory.</p>

<p>I know <code>flatten</code>, <code>ravel</code>, <code>flat</code>, <code>flatiter</code> but I'm still not sure which function will <strong>truly</strong> reflect the memory order?</p>

<p>Probably <code>ravel</code> will suit your needs, if you use the <code>order='K'</code> option. From the <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.ravel.html" rel="nofollow">docs</a>:</p>

<blockquote>
  <p>order : {âCâ,âFâ, âAâ, âKâ}, optional</p>
  
  <p>[...] âKâ means to read the elements in the order they occur in memory, except for reversing the data when strides are negative.[...]</p>
</blockquote>

<p>If you just want to learn more about the memory layout of an array without printing all the elements, you can look at its <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.strides.html" rel="nofollow"><code>strides</code> attribute</a>.</p>

python numpy