This is the code I've got so far:
import numpy as np
def mandelbrot(resol):
R, I = np.meshgrid(np.linspace(-2,.5,resol), np.linspace(1.25j,-1.25j,resol))
Z = R + I
C = np.array(Z)
iterations = np.zeros(Z.shape, dtype=np.uint8)
escape_vals = np.zeros(Z.shape, dtype=np.complex128)
for i in np.arange(MAXITERS):
#only the complex values that haven't diverged get iterated
_ = np.abs(Z) <= 2
Z[_] *= Z[_]; Z[_] += C[_]
#np.invert(_, _) just toggles all of the boolean values in _
#So, wherever np.abs(Z) > 2...
np.invert(_, _)
iterations[_] = i
escape_vals[_] = Z[_]
#Take the last set of points np.abs(Z) > 2,
#invert it; those are the points in the Mandelbrot set.
np.invert(_, _)
iterations[_] = MAXITERS
escape_vals[_] = Z[_]
iterations += 2
escape_vals *= escape_vals; escape_vals += C
escape_vals *= escape_vals; escape_vals += C
moduli = np.array(np.abs(escape_vals), np.float64)
mus = np.array(iterations - np.log(np.log(moduli))/np.log(2))
return mus
My problem is that I am getting modulus values between 0 and 1, and when I take the log of those twice I get nan. I am also not sure of the best way to map these values to my chosen color palette! Does anyone see a mistake I am making?