Optimization, Python, Linear Optimization, Operations Research.
idx in range(0, cost2d.size, len(I)): tmp_constr = { 'type': 'ineq', 'fun': lambda x, idx=idx: M[idx//len(I) + 1] - np.sum(x[idx: idx + len(I)]) } tmp.append(tmp_constr) return tmp list_of_lists = [const1(), const2()] constraints = [item for sublist in list_of_lists for item in sublist] PuLP #