<p dir="auto">A major use case for the <a href="https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.fromfile.html" rel="nofollow">numpy.fromfile()</a> function is in reading from binary file of some kind. Frequently, binary formats are just arrays of data with a fixed-size header. It would be useful to have an extra optional parameter for the fromfile() function which defines a byte offset for when to start reading. This parameter would default to 0, leaving it backwards-compatible with existing code.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np

binary_file = &quot;sample_binary.bin&quot;
my_array = np.fromfile(binary_file, dtype=np.uint8, offset=40)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">binary_file</span> <span class="pl-c1">=</span> <span class="pl-s">"sample_binary.bin"</span>
<span class="pl-s1">my_array</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">fromfile</span>(<span class="pl-s1">binary_file</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>, <span class="pl-s1">offset</span><span class="pl-c1">=</span><span class="pl-c1">40</span>)</pre></div>
<p dir="auto">Currently, the above code will not run, as the 'offset' keyword argument is not supported. In this call, the ndarray object 'my_array' would be the result of the binary file being read in, starting with an offset of 40 bytes.</p>
<p dir="auto">It is certainly possible to <a href="https://stackoverflow.com/questions/30124255/read-a-binary-file-using-numpy-fromfile-and-a-given-offset" rel="nofollow">work-around</a> the issue currently, but adding direct support for offsets in the function would make for cleaner code.</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1412" rel="nofollow">http://projects.scipy.org/numpy/ticket/1412</a> on 2010-02-25 by trac user A_LARAS, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/cournape/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/cournape">@cournape</a>.</em></p>
<p dir="auto">Hi There[[BR]]</p>
<p dir="auto">I'm trying to build scipy from the trunk (latest release):[[BR]]<br>
python setup.py config_fc --fcompiler=gnu95 install --prefix=/usr/local/python[[BR]]<br>
but stuck with the following error :[[BR]]<br>
C compiler: c++_r -qlanglvl=extc89 -DNDEBUG -O[[BR]]</p>
<p dir="auto">compile options: '-Iscipy/interpolate/src -I/usr/local/python/lib/python2.4/site-packages/numpy/core/include -I/usr/local/python/include/python2.4 -c'[[BR]]<br>
c++_r: scipy/interpolate/src/_interpolate.cpp[[BR]]<br>
sh: c++_r:  not found.[[BR]]<br>
sh: c++_r:  not found.[[BR]]<br>
error: Command "c++_r -qlanglvl=extc89 -DNDEBUG -O -Iscipy/interpolate/src -I/usr/local/python/lib/python2.4/site-packages/numpy/core/include -I/usr/local/python/include/python2.4 -c scipy/interpolate/src/_interpolate.cpp -o build/temp.aix-5.3-2.4/scipy/interpolate/src/_interpolate.o" failed with exit status 127[[BR]]</p>
<p dir="auto">whith export CXX="c++", I hit another error (syntax error)[[BR]]<br>
c++ c++ -qlanglvl=extc89 -bI:/usr/local/Python.2.4/lib/python2.4/config/python.exp build/temp.aix-5.3-2.4/scipy/interpolate/src/_interpolate.o -Lbuild/temp.aix-5.3-2.4 -o build/lib.aix-5.3-2.4/scipy/interpolate/_interpolate.so[[BR]]<br>
c++: c++: No such file or directory[[BR]]<br>
c++: unrecognized option '-qlanglvl=extc89'[[BR]]<br>
c++: unrecognized option '-bI:/usr/local/Python.2.4/lib/python2.4/config/python.exp'[[BR]]<br>
error: Command "c++ c++ -qlanglvl=extc89 -bI:/usr/local/Python.2.4/lib/python2.4/config/python.exp build/temp.aix-5.3-2.4/scipy/interpolate/src/_interpolate.o -Lbuild/temp.aix-5.3-2.4 -o build/lib.aix-5.3-2.4/scipy/interpolate/_interpolate.so" failed with exit status 1[[BR]]</p>
<p dir="auto">the second "c++" is passed as an options to CXX compiler, and I don't know how to get rid of this.[[BR]]</p>
<p dir="auto">OS: AIX 5.3  64 bits[[BR]]<br>
CC: gcc (GCC) 4.2.4[[BR]]<br>
CXX: c++ (GCC) 4.2.4[[BR]]<br>
Python: Python 2.4 (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="365753" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/2" data-hovercard-type="pull_request" data-hovercard-url="/numpy/numpy/pull/2/hovercard" href="https://github.com/numpy/numpy/pull/2">#2</a>, Dec 20 2004, 10:36:59) [C] on aix4[[BR]]<br>
Numpy: 1.4[[BR]]</p>