I work with scipy optimize minimize package. In order to provide constraints for my problem I need to create a massive tuple. I do it in the following way:
c0 = [];
count = 0;
for i in range(0, Nx):
for j in range(0, Ny):
c0.append({'type': 'eq', 'fun': lambda x: x[count]*x[count] + x[T + count]*x[T + count] + x[2*T + count]*x[2*T + count] - 1.});
count+=1;
cons = tuple(c0);
But when the minimizer takes them to use, it always takes the terminal value of count
, which obviously results into an index out of bounds
error. Trying del(count)
resulted into another error, so I guess there is something wrong with my understanding of the python way of lambda functions usage. Maybe there is a better, python-style way using slices and stuff? Would appreciate any help.