Code speedup tips

Frank Buss fb at
Sun Mar 9 15:41:30 CET 2003

Frank Buss <fb at> wrote:

> But I think for the calculation of the sum of all 1's, it could be
> faster. Currently it is implemented like this:
> # print the number of '1's for all automaton steps
> for step in range(length / 2):
>   print reduce(lambda x, y: x+y, rule30.current) 
>   rule30.step()
> Where 'current' is a Numeric's array. Any tips?

Changjune Kim sent me the idea, to use ".count(1)". This doesn't work with 
the Numeric array (perhaps it should be added to the Numeric array-class), 
but after ".tolist()" it is 5 times faster: 11 seconds for 5000 arrays of 
size 10000 with tolist().count(1) and 52 seconds for my lambda construct.

for step in range(length / 2):

Frank Buß, fb at,

More information about the Python-list mailing list