我需要生成一个list
对scipy.optimize.minimize
的boundry condition
,就应该是这样的:
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),]
我想知道是否有任何优雅的方式吗?
我试过了:
bonds = [[(0., 0.99),(-30, 30),(-30, 30),(0., 30),(0., 30),(-0.99, 0.99)] for i in range(3)]
但这会产生
[[(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)]]
如何将内部数组移除[]
到unravel
内部数组中?或者还有其他好办法吗?
你可以做:
bonds = [(0., 0.99),(-30, 30),(-30, 30),(0., 30),(0., 30),(-0.99, 0.99)] * 3