scipy - What is the fastest way to minimize a function in python
https://stackoverflow.com/questions/43648073/what-is-the-fastest-way-to-minimize-a-function-in-python
WebApr 27, 2017 · import numpy as np from scipy.optimize import minimize matrix = np.array([[1.0, 1.5, -2.], [0.5, 3.0, 2.5], [1.0, 0.25, 0.75]]) def fct(x): return x.dot(matrix).dot(x) x0 = np.ones(3) / 3 cons = ({'type': 'eq', 'fun': lambda x: x.sum() - 1.0}) bnds = [(0, 1)] * 3 w = minimize(fct, x0, method='SLSQP', bounds=bnds, constraints=cons)['x']
DA: 51 PA: 98 MOZ Rank: 55