numpy.fromfile differences between python 2.7.3 and 2.7.6
<p>I'm having an issue running code between two consoles and I've gotten it down to a difference between the versions of python installed on these computers (2.7.3 and 2.7.6 respectively). </p>

<p>Here is the input file found on github (<a href="https://github.com/tkkanno/PhD_work/blob/master/1r" rel="nofollow">https://github.com/tkkanno/PhD_work/blob/master/1r</a>).</p>

<p>when in python 2.7.3 and numpy version 1.11.1 the following code works as expected:</p>

<pre><code>import numpy as np
s  = 'directory/to/file'
f = open(s, 'rb')
y = np.fromfile(f,'&lt;l')
y.shape
</code></pre>

<p>this give gets an numpy array of shape (16384,). However, when it is run on python 2.7.6/numpy 1.11.1 it gives an array half the size (8192,). This isnt' acceptable for me</p>

<p>I can't understand why numpy is acting this way with different versions of python. I would be grateful for any suggestions</p>

<p>Converted from <a href="https://stackoverflow.com/questions/39880198/numpy-fromfile-differences-between-python-2-7-3-and-2-7-6/39900392#comment67047204_39880198">my comment</a>:</p>

<p>You're likely running on different Python/OS builds with different notions of how big a <code>long</code> is. C doesn't require a specific <code>long</code> size, and in practice, Windows always treats it as 32 bits, while other common desktop OSes treat it as 32 bits if the OS &amp; Python are built for 32 bit CPUs (ILP32), and 64 bits if built for 64 bit CPUs (LP64).</p>

<p>If you want a fixed width type on all OSes, don't use the system-dependent-width types. <a href="https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#arrays-dtypes-constructing" rel="nofollow">Use fixed width types instead</a>. From your comments, the expected behavior is to load 32 bit/4 byte values. If you were just using native endianness, you could just pass <code>numpy.int32</code> (<code>numpy</code> recognizes the raw <code>class</code> as datatypes). Since you want to specify endianness explicitly (perhaps this might run on a big endian system), you can instead pass <code>'&lt;i4'</code> which explicitly states it's a little endian (<code>&lt;</code>) signed integer (<code>i</code>) four bytes in size (<code>4</code>):</p>

<pre><code>import numpy as np
s  = 'directory/to/file'
with open(s, 'rb') as f:       # Use with statements when opening files
    y = np.fromfile(f, '&lt;i4')  # Use explicit fixed width type
y.shape
</code></pre>

python arrays numpy