General Numerical Python question

2mc mcrider at bigfoot.com
Mon Oct 13 23:15:35 EDT 2003


Michael Ressler <ressler at cheetah.jpl.nasa.gov> wrote in message news:<slrnbolkk2.89o.ressler at cheetah.jpl.nasa.gov>...
> The real question is - why do you want to run a loop over an array?
> The whole point of Numeric is that you want to eliminate loops
> entirely. Keeping things in the array domain is infinitely faster than
> running explicit loops. You may need to come up with some clever
> expressions to do it, but most loops can be gotten rid of with clever
> uses of put(), take(), and the like.
> 
> Loops are evil.
> 
> Mike

For me, the key thought in your post is " you may need to come up with
some clever expressions to do it, but most loops can be gotten rid of
with clever uses of put(), take(), and the like."

This is what I'm looking for.  I'm so used to explicitly declaring
loops that it is hard for me to "speak" in Numerical Python.

Suppose I have 2 very large arrays of serial data.  To make it simple,
let's assume each has 10s of thousands of rows with one column/field
of data.  Further assume at some point later in the program I am going
to compare the data in the two arrays - the comparison being on chunks
of 25 rows throughout the array.  But, before I do that, I have to
"normalize" the data in both arrays in order to make the comparisons
valid.

Assume the way I make the comparisons is to find the size of the range
between the highest and the lowest value in each 25 row 'chunk' and
normalize each data point as: (datapoint - lowestvalue) /
(highestvalue - lowestvalue) * 100.

Then assume I want to find the slope of the linear regression through
each 25 row 'chunk.'  It is this slope that I will ultimately be
comparing later in the program.

This is the kind of programming I was hoping I could use Numerical
Python for.  It is the syntax of such a program that I'm grappling
with.  If someone could help me with the above scenario, then I could
write the program using the real comparisons I want (which are
considerably more complicated than above).

Thank you for your kind response.  If you have any comments on the
above I would appreciate hearing them.

Matt




More information about the Python-list mailing list