
Python 3 code
###########################################
# 2D Mandelbrot set with complex arrays
# (matplotlib module)
###########################################
import numpy as np           # import numpy module
import matplotlib.pyplot as plt      # import matplotlib module
 n = 8 # set number of cycles
Cx = -.8 # set initial x parameter shift
Cy = 0.0 # set initial y parameter shift
L = 1.7 # set square area side
M = 2024 # set side number of pixels

x = np.linspace(Cx-L,Cx+L,M) # x variable array
y = np.linspace(Cy-L,Cy+L,M) # y variable array
X,Y = np.meshgrid(x,y,sparse=True) # square area grid
Z = np.zeros(M) # complex starting points area
C = X + 1j*Y # complex plane area

for k in range(1,n+1): # recursion cycle
  Z1 = Z**2 + C  # alternative Z1 = Z**4 + C
  Z = Z1
W = np.e**(-abs(Z)) # smoothed sum moduls

plt.imshow(W,interpolation=’nearest’, cmap=plt.cm.nipy_spectral)
plt.axis("off")
plt.show()              # plot image
