"sum_entries" function along an axis in cvxpy


(Bobby) #1

I am using CVX in Python. I have a boolean variable that is an nxn matrix (let’s call this matrix X). And I have a constraint where I sum across the rows of X.

I am trying to use “sum_entries(X , axis=0) == 1” for the constraint, but I am getting the following error:

TypeError: init() got an unexpected keyword argument ‘axis’

According to the documentation, this function is completely legal: http://www.cvxpy.org/en/latest/tutorial/functions/index.html#functions-along-an-axis

Does anyone have any idea why I am getting this error?

Here is the sample code:

from cvxpy import *
import numpy as np

n = 5
X = Bool(n , n)
Y = Bool(n , 1)
C = np.random.randint(1,5,(n,n))

objective = Minimize( sum_entries( mul_elemwise(C, X) )  )
constraints = []
constraints.append( sum_entries( X, axis=0 ) == 1 )
constraints.append( sum_entries( X, axis=1 ) <= 100*Y )
constraints.append( sum_entries(Y) == C )
    
prob = Problem(objective, constraints)
prob.solve(solver='GUROBI',verbose = True)

(Mark L. Stone) #2

cvxpy is not CVX, and is out of scope of the CVX forum. However, there is a cvxpy forum at https://groups.google.com/forum/#!forum/cvxpy .


(Michael C. Grant) #3