"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > In order to make sure all variables be larger than 0, I tried to created > constraint function like this: > > cons = [] > for i in range(N): > c = lambda x: x[i] - 1e-10 > cons.append(c) > > But when functions in cons are evaluated, the value in all functions are > all the same(N-1, which is the last value of i in the loop). > > What I want is, when functions in cons be evaluated, every function > refers to a different variable in X.
So pass i in as a default value: for i in range(N): def c(x, i=i): return x[i] - 1e-10 cons.append(c) -- http://mail.python.org/mailman/listinfo/python-list