class RandomDisplacementBounds(object):
    """random displacement with bounds"""

def __init__(self, xmin, xmax, stepsize=0.5):
    self.xmin = xmin
self.xmax = xmax
self.stepsize = stepsize

def __call__(self, x):
    """take a random step but ensure the new position is within the bounds"""
while True:
    xnew = x + np.random.uniform(-self.stepsize, self.stepsize, np.shape(x))
if np.all(xnew < xmax) and np.all(xnew > xmin):
    break
return xnew
take_step = RandomDisplacementBounds(xmin, xmax)
result = basinhopping(f, x0, niter=100, minimizer_kwargs=minimizer_kwargs,
    take_step=take_step)
print(result)
how to find global minimum in python optimization with bounds?