jepler at unpythonic.net
Fri Jul 9 02:41:03 CEST 2004
Here's a program which calculates a similar result to yours using
numarray. It calculates a 50x50 grid to 500 iterations in 3 seconds on
a 750MHz machine. I didn't run yours so I don't know how this compares.
Hm, timeit.py says that your function runs in 2 ms per point with DEPTH=500
given the point 0+0j, and of course runs faster on points that escape.
Your program may run faster than the numarray implementation, or it
might be a wash. (2ms * 50 * 50 == 5 seconds)
This isn't a natural application for numarray.
from numarray import *
DEPTH = 500
def coords(x0, y0, x1, y1, w, h):
rx = arange(w).astype(Float32) * (x1-x0) / (w-1) + x0
ry = arange(w).astype(Float32) * (y1-y0) / (h-1) + y0
return add.outer(rx * 1j, ry)
C = z.copy()
d = zeros(z.shape)
for c in range(DEPTH):
z = z*z - C
zz = abs(z) > 3
#print zz; print
d += where(zz, 1, 0)
if not (c % 8): # keep contents of z from overflowing
z = where(zz, 10, z)
# 20x20 prints nicely on the screen in numbers
c = coords(-1.5, -1.5, 1.5, 1.5, 20, 20)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Python-list