# REPOST: Re: Efficient storage of floats

Chris Barker chrishbarker at attbi.com
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
(http://sourceforge.net/projects/numpy):

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

-Chris

--
Christopher Barker,
Ph.D.
ChrisHBarker at attbi.net                ---           ---           ---
---@@       -----@@       -----@@
------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool0-milwwi.newsops.execpc.com!newsfeeds.sol.net!newspump.sol.net!newsfeed.direct.ca!look.ca!nntp.kreonet.re.kr!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Chris Barker <chrishbarker at attbi.com>
Newsgroups: comp.lang.python
Subject: cmsg cancel <3C2B720F.209C3A04 at attbi.com>
Control: cancel <3C2B720F.209C3A04 at attbi.com>
Date: Mon, 31 Dec 2001 02:36:31 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.3C2B720F.209C3A04 at attbi.com>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009775672 27193 211.57.49.2 (31 Dec 2001 05:14:32 GMT)
X-Complaints-To: usenet at news2.kornet.net
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.

```