Search code examples
pythoncvxpy

Got warning: warnings.warn(msg, UserWarning)


I try to use cvxpy by using this code

`# Number of variables n = len(symbols)

The variables vector

x = Variable(n)

The minimum return

req_return = 0.02

The return

ret = r.T*x

The risk in xT.Q.x format

risk = quad_form(x, C)

The core problem definition with the Problem class from CVXPY

prob = Problem(Minimize(risk), [sum(x)==1, ret >= req_return, x >= 0])`

And I got warning

C:\Users\LENOVO\anaconda3\lib\site-packages\cvxpy\expressions\expression.py:593: UserWarning: 
This use of ``*`` has resulted in matrix multiplication.
Using ``*`` for matrix multiplication has been deprecated since CVXPY 1.1.
    Use ``*`` for matrix-scalar and vector-scalar multiplication.
    Use ``@`` for matrix-matrix and matrix-vector multiplication.
    Use ``multiply`` for elementwise multiplication.
This code path has been hit 2 times so far.

  warnings.warn(msg, UserWarning)
```
`




Try to solve the warning  and no idea about warning

Solution

  • It's Warning mean your code run properly so Let's see the warning


    The Warning tell us that

    Using ``*`` for matrix multiplication has been deprecated since CVXPY 1.1.
    

    so you already use CVXPY version upper 1.1 How to solve:

        Use ``*`` for matrix-scalar and vector-scalar multiplication.
    Use ``@`` for matrix-matrix and matrix-vector multiplication.
    Use ``multiply`` for elementwise multiplication.
    

    If ret = r.T*x cannot run you can try ret = r.T @x from CVXPY DOC