[SciPy-user] reading (labview) binary data

Emanuele Olivetti emanuele@relativita....
Wed Jul 15 08:47:17 CDT 2009

Michael Graber wrote:
> hi all,
> i'm looking for the fastest way to read (labview) binary files.
> i figured out a method which is basically the same as described on:
> http://www.shocksolution.com/2008/06/25/reading-labview-binary-files-with-python/
> that is:
> binaryFile = open("Measurement_4.bin", mode='rb')
> (data.offset,) = struct.unpack('>d', binaryFile.read(8))
> but this is terribly slow. to read 12 MB takes about 80 seconds.  
> matlab is orders of magnitude faster ..
> is there a better, i.e. faster way to read in (labview) binary files?

Try numpy.fromfile(). Example:

import numpy as np
f = open('<filename>','rb')
data = np.fromfile(f, dtype='>d') # reads the whole file
print data.shape

'data' should now be a vector of big-endian doubles from the whole file.
If you want to parse just a subset of all doubles within the file use the
optional argument 'count='. See np.fromfile() docstring.



More information about the SciPy-user mailing list