2

これは私がこれまでに得たコードです:

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

私の問題は、0 と 1 の間のモジュラス値を取得していることです。それらのログを 2 回取得すると、nan が取得されます。また、これらの値を選択したカラー パレットにマップする最善の方法もわかりません。私が犯している間違いを見た人はいますか?

4

0 に答える 0