I need to generate a list
for scipy.optimize.minimize
's boundry condition
, it should look like this:
bonds = [(0., 0.99),(-30, 30),(-30, 30),(0., 30),(0., 30),(-0.99, 0.99),
(0., 0.99),(-30, 30),(-30, 30),(0., 30),(0., 30),(-0.99, 0.99),
(0., 0.99),(-30, 30),(-30, 30),(0., 30),(0., 30),(-0.99, 0.99),]
I'm wondering if there is any elegant way of doing it?
I tried:
bonds = [[(0., 0.99),(-30, 30),(-30, 30),(0., 30),(0., 30),(-0.99, 0.99)] for i in range(3)]
But this generates
[[(0.0, 0.99), (-30, 30), (-30, 30), (0.0, 30), (0.0, 30), (-0.99, 0.99)],
[(0.0, 0.99), (-30, 30), (-30, 30), (0.0, 30), (0.0, 30), (-0.99, 0.99)],
[(0.0, 0.99), (-30, 30), (-30, 30), (0.0, 30), (0.0, 30), (-0.99, 0.99)]]
How can I remove the inner []
, to unravel
the inner arrays into a single one? Or is there any other good way of doing it?