Reading IEEE 754 format strings directly into a floating point array

M

Madhusudan Singh

I am querying an instrument in a measurement application.

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 ?

Alternatively, I could write a routine to do it, but wanted to find out if
there was a simpler solution.
 
R

Robert Kern

Madhusudan said:
I am querying an instrument in a measurement application.

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 ?

Alternatively, I could write a routine to do it, but wanted to find out if
there was a simpler solution.

http://docs.python.org/lib/module-array.html
http://numeric.scipy.org

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
B

Ben Caradoc-Davies

Madhusudan said:
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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top