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] 

```
I will start by mentioning that *quadratic programming* problems are a subset of *convex optimization* problems which are a subset of *optimization* problems.

There are multiple python packages which solve quadratic programming problems, notably

1. [cvxopt](https://cvxopt.org/userguide/coneprog.html#quadratic-programming) -- which solves all kinds of *convex optimization* problems (including quadratic programming problems). This is a python version of the previous [cvx MATLAB package](http://cvxr.com/cvx/).
2. [quadprog](https://github.com/rmcgibbo/quadprog) -- this is exclusively for quadratic programming problems but doesn't seem to have much documentation.
3. [scipy.optimize.minimize](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) -- this is a very general minimizer which can solve quadratic programming problems, as well as other *optimization* problems (convex and non-convex).

You might also benefit from looking at the answers to [this stackoverflow post](https://stackoverflow.com/questions/17009774/quadratic-program-qp-solver-that-only-depends-on-numpy-scipy) which has more details and references.

Note: The code snippet in user1911226' answer appears to come from this blog post:
<https://scaron.info/blog/quadratic-programming-in-python.html>
which compares some of these quadratic programming packages. I can't comment on their answer, but they claim to be mentioning the cvxopt solution, but the code is actually for the quadprog solution.