Situation: I am using the scipy for an optimization problem. For many constraints are needed, the coefficients are in a pandas.dataframe object. I am trying to input all these constraints using cycles. the problem is in the next cycle, the parameters have been changed, so there is only on constraints remained actually.
to express the problem more clearly, I give an example(in this example, just a few parameters is given. But in the actual situation, maybe there are more than 50 paramters).
Step1: the code I used is something as follows:
the constraints is w1 + w2 * 2 >= 0; w1 * 3 + w2 * 5 >= 0
cons = []
d = {
'type': 'ineq',
'fun': ''}
a = np.array([1,2])
d['fun'] = lambda w: a.dot(w)
cons.append(d.copy())
a = np.array([3,5])
d['fun'] = lambda w: a.dot(w)
cons.append(d.copy())
cons
Step2: test the cons using the code shown as follows: just using w as [1, 1], I expect the fun stored in cons will output 3 and 8, but actually 8 and 8.
w = np.array([1,1])
for each in cons:
fun = each['fun']
print(fun(w))
Can anyone give some help on how to solve this problem? Or it's just something wrong.