REPOST: Re: Efficient storage of floats

Chris Barker chrishbarker at
Thu Dec 27 20:10:07 CET 2001

Francois Petitjean wrote:
> I have to read a number of points coordinates (npoints). Different
> structures can be used to store these numbers:

> 2. The coordinates can be stored in an array
> acoords = array.array('f')

This is crying out to be done with Numeric Arrays

import Numeric:

coords = Numeric.zeros((3,npoints),Numeric.Float)

> Using acoords : x,y,z = acoords[3*kpt],acoords[3*kpt+1],acoords[3*kpt+2]

x,y,z = acoords(n)

The possible n-d arrays of Numeric make this kind of thing MUCH easier,
and you will get the efficient storage you want. Numeric arrays use the
same amont of storage a C array would use for the same type, plus the
overhead of the Array object, which would be negligable compared to the
data for a large array.

Asside for that, you now have a data an object type that supports
effiecent computation, wiht nice easy notation:

transformed_coords = acoords * 5

to multiply all the coordanates by 5, or:

transformed_coords = acoords * (x_scale, y_scale, z_scale)

Etc, etc, etc.

If you are working with a lot of numbers, you are crazy not to use


Christopher Barker,
ChrisHBarker at                ---           ---           ---
                                     ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------

========= WAS CANCELLED BY =======:
From: Chris Barker <chrishbarker at>
Newsgroups: comp.lang.python
Subject: cmsg cancel <3C2B720F.209C3A04 at>
Control: cancel <3C2B720F.209C3A04 at>
Date: Mon, 31 Dec 2001 02:36:31 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.3C2B720F.209C3A04 at>
X-Trace: 1009775672 27193 (31 Dec 2001 05:14:32 GMT)
X-Complaints-To: usenet at
NNTP-Posting-Date: Mon, 31 Dec 2001 05:14:32 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.

More information about the Python-list mailing list