Reading binary file in c written in python
<p>I wrote numpy 2 dimensional float array as a binary file using </p>

<p><code>narr.tofile(open(filename,"wb"),sep="",format='f')</code> </p>

<p>and try to retrieve the same in c using</p>

<pre><code>FILE* fin = fopen(filename,"rb") 
float* data = malloc(rows*2*sizeof(float));
fread(data, sizeof(float), rows*2, fin);
</code></pre>

<p>This data array when printed shows different values than original array. Am I missing something?
Thanks</p>

<p>It may depends on system you are using, <code>ndarray.tofile()</code> outputs in little-endian, which means that the  <strong>least significant byte is stored first</strong>, try to use <code>numpy.byteswap()</code> and then convert to file. Also try to do it without format specifier and see result. Documentation states that default value for specifier is <code>format="%s"</code>, try to put percentage symbol before your format specifier, like so <code>%f</code>. </p>

python c arrays numpy