6

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.

taras
  • 6,566
  • 10
  • 39
  • 50
goldenbear137
  • 81
  • 1
  • 1
  • 4
  • Please show an example of the code you have, and describe what you've tried so far. Refer to this http://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. – Metropolis Apr 11 '17 at 01:17

1 Answers1

6

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.

captaincapsaicin
  • 950
  • 1
  • 7
  • 15