Code speedup tips
Frank Buss
fb at frank-buss.de
Sun Mar 9 09:41:30 EST 2003
Frank Buss <fb at frank-buss.de> 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):
print(rule30.current.tolist().count(1))
rule30.step()
--
Frank Buß, fb at frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
More information about the Python-list
mailing list