Neither scipy.optimize.fmin nor scipy.optimize.leastsq seem to play good with complex numbers. For example, fmin(lambda x: np.linalg.norm(x - np.array((1.2, 3+2j))), np.array((0j, 0j))) converges to array([ 1.19996429, 2.99997809]) , and leastsq just fails. To make it work, I would put your complex numbers in R ^ 2, I think. So that,
fmin(lambda x: np.linalg.norm(x - np.array((1.2, 0, 3,2))), np.array((0,0, 0,0)))
which converges to
array([ 1.20000095e+00, -4.11719096e-05, 2.99999705e+00, 2.00001270e+00])
But yes, it would be nice if these functions played well with complex numbers.
source share