how do you convert and array of doubles into floats?

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


>> 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.

I skimmed the docs of array and saw 'floating point' in both, assuming 
they were the same. Rereading them I actually recognized the "minimum 
size in bytes" column - and that is 4 for "f" and 8 for "double".

If I were in "pardoning" mode, I'd say "but minimum doesn't exclude the 
possibility of floats having 8 bytes" - but I'm not :) So, I stand 
corrected.

Thanks,

Diez



More information about the Python-list mailing list