how do you convert and array of doubles into floats?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri Sep 15 15:26:00 EDT 2006
In <4n090tF88jknU1 at uni-berlin.de>, Diez B. Roggisch wrote:
> Marc 'BlackJack' Rintsch schrieb:
>> In <1158342034.282295.144660 at i3g2000cwc.googlegroups.com>, SpreadTooThin
>> wrote:
>>
>>> 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?
>>
>> What about:
>>
>> b = array.array('f', a)
>
> AFAIK d and f are synonym for arrays, as python doesn't distinguish
> between these two on a type-level. And double it is in the end.
No `array.array` is really about "C compiler types". You get C doubles in
form of Python's `float` type if you read from the `array.array` but it's
stored as C float and you can get the binary representation with the
`tostring()` method.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list