Skip to content

Instantly share code, notes, and snippets.

@DavidButts
Created January 26, 2018 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidButts/ffe83e4b459994a788096f22bed4a6d3 to your computer and use it in GitHub Desktop.
Save DavidButts/ffe83e4b459994a788096f22bed4a6d3 to your computer and use it in GitHub Desktop.
import time
import numpy as np
from numba import jit
x_dim = 1000
y_dim = 1000
x_min = -1.8
x_max = 1.8
y_min = -1.8j
y_max = 1.8j
z = np.zeros((y_dim,x_dim),dtype='complex128')
for l in range(y_dim):
z[l] = np.linspace(x_min,x_max,x_dim) -np.linspace(y_min,y_max,y_dim)[l]
@jit()
def julia_numpy_numba(c,z):
it = 0
max_iter = 100
while(it < max_iter):
z[np.absolute(z) < 10] = z[np.absolute(z) < 10]**2 + c #the logic in [] replaces our if statement. This line
it += 1 #updates the whole matrix at once, no need for loops!
return z
start = time.perf_counter()
julia_numpy_numba(-.4+.6j,z)
end = time.perf_counter()
print(end-start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment