Element-wise multiplication in CVXPY
Asked Answered
B

1

7

I am trying to do element-wise multiplication in CVXPY in the objective function. Is this allowed as part of a convex problem?

X is a n x 1 variable. V is a n x n constant.

I want to do the equivalent of np.multiply(X, V*X), which returns an n x 1 vector.

Bove answered 11/4, 2017 at 0:52 Comment(1)
Please show an example of the code you have, and describe what you've tried so far. Refer to this stackoverflow.com/help/how-to-ask for more detail on how to ask a good question to maximize your chances of getting a helpful answer.Catarinacatarrh
F
7

I think the function you're looking for is cvx.multiply

For example:

In [1]: import cvxpy as cvx

In [2]: n = 10

In [3]: X = cvx.Variable((n, 1))

In [4]: V = cvx.Variable((n, n))

In [5]: cvx.multiply(X, V*X)
Out[5]: Expression(UNKNOWN, UNKNOWN, (10, 1))

In the 1.0 update notes, they mention that this function used to be called mul_elemwise (<1.0), which may have been the source of your confusion.

Frowst answered 19/5, 2018 at 8:6 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.