file data => array(s)
Eric
einazaki668 at yahoo.com
Thu Dec 15 13:51:03 EST 2011
On Dec 14, 5:27 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Wed, 14 Dec 2011 14:20:40 -0800, Eric wrote:
> > I'm trying to read some file data into a set of arrays. The file data
> > is just four columns of numbers, like so:
>
> > 1.2 2.2 3.3 0.5
> > 0.1 0.2 1.0 10.1
> > ... and so on
>
> > I'd like to read this into four arrays, one array for each column.
> > Alternatively, I guess something like this is okay too:
>
> > [[1.2, 2.2, 3.3, 0.5], [0.1, 0.2, 1.0, 10.1], ... and so on]
>
> First thing: due to the fundamental nature of binary floating point
> numbers, if you convert text like "0.1" to a float, you don't get 0.1,
> you get 0.10000000000000001. That is because 0.1000...01 is the closest
> possible combination of fractions of 1/2, 1/4, 1/8, ... that adds up to
> 1/10.
>
> If this fact disturbs you, you can import the decimal module and use
> decimal.Decimal instead; otherwise forget I said anything and continue
> using float. I will assume you're happy with floats.
>
Yeah, I don't think it'll be a problem. As I understand it a float in
python is a double in C and all our old C programs used doubles. From
PDP-11 to MIPS3k to P2 I've seen what I think may have been rounding
or precision errors but I haven't heard any complaints because of
them.
Thanks,
eric
More information about the Python-list
mailing list