Reading IEEE 754 format strings directly into a floating point array
Ben Caradoc-Davies
ben at wintersun.org
Fri Oct 14 23:59:41 EDT 2005
Madhusudan Singh wrote:
> The values are returned as IEEE format binary floating point numbers. There
> are 4 bytes per point. Multiple points are not separated by any delimiter.
> Is it possible to read these directly into a floating point array of the
> size of the string ?
Consider using the struct module from the standard library, with format
"f". It also allows you to specify endianness in a platform-independent
manner, and for mixed formats, supports standard and native alignment.
http://docs.python.org/lib/module-struct.html
You have a string of length 4*n, so make a format with (for example)
">"+"f"*n, and struct.unpack will return a tuple of length n.
For large volumes of data, the array module may be more useful (as
someone else has already noted).
--
Ben Caradoc-Davies <ben at wintersun.org>
http://wintersun.org/
"Those who deny freedom to others deserve it not for themselves."
- Abraham Lincoln
More information about the Python-list
mailing list