[SciPy-user] Problem with reading binary file (diffrener resultbetween MATLAB and Python)

Robert Kern robert.kern@gmail....
Sun Jan 11 18:55:32 CST 2009


On Sun, Jan 11, 2009 at 08:44, Hani Zahiri <H.Zahiri@curtin.edu.au> wrote:
> Hi Robert,
>
> Many Thanks, you were right and it's work. Since, I run both MATLAB and
> Python on windows, I didn't suspect byte order issue.
> Probably, original file was generated using different byte order. Is it
> the case that MATLAB can recognise the original byte order (because it
> is platform-independent) and Python does not?!

No, you are explicitly telling MATLAB that the file is big-endian when
you use 'b' (short for 'ieee-be') as the third argument to fopen(). In
Python, the file objects neither know nor care about integer formats;
they just give bytes. You have to use that knowledge when you convert
to a numpy object by picking the right dtype.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-user mailing list