Mandelbrot Microscope
Jeff Epler
jepler at unpythonic.net
Thu Jul 8 20:41:03 EDT 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)
def f(z):
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)
return d
# 20x20 prints nicely on the screen in numbers
c = coords(-1.5, -1.5, 1.5, 1.5, 20, 20)
print f(c)/10
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040708/ad0b7523/attachment.sig>
More information about the Python-list
mailing list