goldenbear137
goldenbear137

Reputation: 91

Element-wise multiplication in CVXPY

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.

Upvotes: 7

Views: 14323

Answers (1)

captaincapsaicin
captaincapsaicin

Reputation: 960

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.

Upvotes: 7

Related Questions