How do I find the maximum of a function in Python? I could try to hack together a derivative function and find the zero of that, but is there a method in numpy (or other library) that can do it for me?
numpy
You can use scipy.optimize.fmin on the negative of your function.
scipy.optimize.fmin
def f(x): return -2 * x**2 + 4 * x max_x = scipy.optimize.fmin(lambda x: -f(x), 0) # array([ 1.])