- #1

member 428835

I'm trying to minimize a function func via scypi's minimiz function, as shown below.

Python:

```
import numpy as np
import scipy.optimize as optimize
def func(x):
y = x[0]**2 + (x[1]-5)**2
print('hi')
return y
bnds = [(1, None), (-0.5, 4)]
result = optimize.minimize(func, method='TNC', bounds=bnds, x0=2 * np.ones(2))
print(result.x)
```

The issue is for every descent toward the minimum the entire func is being evaluated, evidenced by 'hi' being printed several times. Is there a way to avoid this, so that y is evaluated and stored externally so that it does not get executed every descent?

Thanks so much!