See inline comments for details. Use scipy, mystic, or whatever library as you see fit.
import numpy as np from scipy.optimize import differential_evolution,