how do you convert and array of doubles into floats?

Diez B. Roggisch deets at nospam.web.de
Fri Sep 15 14:02:00 EDT 2006


SpreadTooThin schrieb:
> I have some code...
> 
> import array
> 
> a = array.array('d')
> f = open('file.raw')
> a.fromfile(f, 10)
> 
> now I need to convert them into floats (32 bit...) what do i do?

I guess module struct is your friend.

Something like this:

struct.pack("f" * len(a), *a)



Diez



More information about the Python-list mailing list