Skip to content
Advertisement

Generating constraints for optimization in scipy using loop

There are lots of constraints which I will use in optimization using scipy; so I need to generate the constraints by loop. Below there’s a sample of my constraints:

JavaScript

There constraints are more than three… I use following loop to generate but I couldn’t get the same output.

JavaScript

Advertisement

Answer

You are updating cons everytime. Try this

JavaScript

And this is more pythonic

JavaScript
Advertisement