PyMandelbrot package
PyMandelbrot.mandelbrot module
This module implements the base class to compute the Mandelbrot dynamics.
- class PyMandelbrot.mandelbrot.MandelbrotDynamics(z0: Optional[ndarray] = None, c: Optional[ndarray] = None, clip_value: float = 4.0)[source]
Bases:
objectImplementation of the f(z) = z**2 + c function for the Mandelbrot Dynamics.
Examples
One Mandelbrot dynamics iteration:
>>> import numpy as np >>> from PyMandelbrot.mandelbrot import MandelbrotDynamics >>> cs = np.linspace(-1,1,5) # offset parameter >>> cs array([-1. , -0.5, 0. , 0.5, 1. ]) >>> z0s = np.zeros_like(cs) # starting point >>> z0s array([0., 0., 0., 0., 0.]) >>> dynamics = MandelbrotDynamics(z0s, cs) >>> z1s = dynamics() >>> z1s array([-1. , -0.5, 0. , 0.5, 1. ])
n = 4iterations:>>> z4s = dynamics.n_steps(n=4) >>> z4s array([ 0. , -0.30859, 0. , 1.62890, 26. ])
Divergency speed calculation:
>>> it = dynamics.get_divergency_iter() >>> it array([20, 20, 20, 5, 2], dtype=int16)
- property c: ndarray
Offset parameter property.
- check_params()[source]
Checks parameters are set.
- Raises
ValueError – If either starting point z0 or offset parameter c is None.
- get_divergency_iter(threshold: float = 4.0, max_iter: float = 20) ndarray[source]
Computes the number of iteration needed by the dynamics to exceed some threshold.
Given the stored starting point, it computes the number of steps for the dynamics modulusu to exceed a given threshold.
- Parameters
threshold (float) – The threshold above which the dynamics is considered divergent.
max_iter (int) – The maximum number of steps to be evaluated.
- Returns
The iteration number at which the dynamics has diverged.
- Return type
np.ndarray
- n_steps(n: int)[source]
Computes n steps of the Mandelbrot dynamics for the given starting point.
- Parameters
z0 (np.ndarray) – Starting points of the Mandelbrot dynamic.
n (int) – Number of steps of the Mandelbrot dynamics.
- property z0: ndarray
Starting point property.