I'm trying to maximize a (scalar) function in Python using scipy.minimize_scalar. Thought it would be more elegant to use lambda instead of defining a new function that's the negative of the given function. Unfortunately, it's giving a TypeError. Here's a simple example:
from scipy.optimize import minimize_scalar
def square(x):
return -(x-1)**2
print(minimize_scalar(lambda x:-square(x),bounds=(0,None),method='bounded'))
Here's the error message I get:
TypeError: '>' not supported between instances of 'int' and 'NoneType'
What's wrong with this example code?
Thanks