I am in the process of translating some MATLAB code into Python. There is one line that is giving me a bit of trouble:

```
[q,f_dummy,exitflag, output] = quadprog(H,f,-A,zeros(p*N,1),E,qm,[],[],q0,options);

```

I looked up the documentation in MATLAB to find that the quadprog function is used for optimization (particularly minimization). 

I attempted to find a similar function in Python (using numpy) and there does not seem to be any. 

Is there a better way to translate this line of code into Python? Or are there other packages that can be used? Do I need to make a new function that accomplishes the same task? 

Thanks for your time and help!
['https://Stackoverflow.com/questions/51161348', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9645799/']
There is a library called [CVXOPT](https://scaron.info/blog/quadratic-programming-in-python.html) that has quadratic programming in it.

```
def quadprog_solve_qp(P, q, G=None, h=None, A=None, b=None):
    qp_G = .5 * (P + P.T)   # make sure P is symmetric
    qp_a = -q
    if A is not None:
        qp_C = -numpy.vstack([A, G]).T
        qp_b = -numpy.hstack([b, h])
        meq = A.shape[0]
    else:  # no equality constraint
        qp_C = -G.T
        qp_b = -h
        meq = 0
    return quadprog.solve_qp(qp_G, qp_a, qp_C, qp_b, meq)[0] 

```
You could use the [`solve_qp`](https://scaron.info/doc/qpsolvers/quadratic-programming.html#qpsolvers.solve_qp) function from [qpsolvers](https://github.com/stephane-caron/qpsolvers). It can be installed, along with a starter kit of open source solvers, by `pip install qpsolvers[open_source_solvers]`. Then you can replace your line with:

```py
from qpsolvers import solve_qp

solver = "proxqp"  # or "osqp", "quadprog", "cvxopt", ...
x = solve_qp(H, f, G, h, A, b, initvals=q_0, solver=solver, **options)

```

There are many solvers available in Python, each coming with their pros and cons. Make sure you try [different values](https://github.com/stephane-caron/qpsolvers#solvers) for the `solver` keyword argument to find the one that fits your problem best.

Here is a standalone example based on your question and the other comments:

```py
import numpy as np

from qpsolvers import solve_qp

H = np.array([[4.0, 1.0], [1.0, 2.0]])
f = np.array([1.0, 1])
G = np.array([[1.0, 0.0], [0.0, 1.0]])
h = np.array([0.7, 0.7])
A = np.array([[1.0, 1.0]])
b = np.array([1.0])
q_0 = np.array([1.0, 1.0])

solver = "cvxopt"  # or "osqp", "proxqp", "quadprog", ...
options = {"verbose": True}
x = solve_qp(H, f, G, h, A, b, initvals=q_0, solver=solver, **options)

```