Need help resolving accidental (honest!) language pissing match

Terry Reedy tjreedy at udel.edu
Wed Jun 2 12:03:01 EDT 2004


"has" <has.temp2 at virgin.net> wrote in message
news:69cbbef2.0406020615.7540ad0 at posting.google.com...
> <BLUSH> Careless talk costs lives, as they say. In my case, a
...
> stupid and incompetent to do it all by myself. :p

Perhaps you should squirm on your own petard a bit, but here are some
comments ;-)

> "Suppose I want to study a random walk. Say I would like to appreciate
> the distribution of the presence of the walker."
>
>     set n to 1000000 -- we'll be talking about 4 MB

There is no need to save a million of anything that i can see.  If there
were, preallocate the list with "array = n*[1]

>     set x to randomarray n range {-1, 1} -- n random draws

This is slightly unclear.  Without the unneeded array, perhaps you mean
something like
x = 0
for i in xrange(n):
    x += random.random() < .5 and -1 or 1

>     set x to runningsum x -- the cumulative sums of the draws

The above does that as you draw.

>     set {mean:the_mean, stdev:the_stdev} to statlist x -- compute
> stats

stats other that x itself are only meanful across multiple walks (ie, m
walks of n steps each).  Since you have not specified m, I am not sure what
you have in mind.  To keep x**2 fitting within an int instead of long, n =
100,000 would be better.

> All the real work here's being done by a C-based scripting addition
> (plugin), taking about a second on a G4/867.

If the int sums are done in C in the addition (aha! this must bei the
reason to make an array), Numerical Python will not do better and maybe not
as well.

If that C addition does floating point in C much like NumPy, then perhaps
AppleScript is less underpowered than you claim.

If the worst comes to the
> worst, I can force a dishonorable draw simply by calling the same
> scripting addition via MacPython's Carbon support modules, but I'd
> really like to punt the blighter out of the ballpark

Unlikely if the C addition is any good.  Anyway, why?  The competitive
advantage of Python is programming speed, especially for larger problems
than this.

>so existing
> C-based Python extensions, Python-to-Fortran bridges, etc. are all
> okay by me if anyone has a few minutes and spot of sympathy to point
> us in the right direction. Cheers! :)

If Psyco runs on Apple, try that.  Otherwise, make arrays and use NumPy.

Terry J. Reedy







More information about the Python-list mailing list