0

I am new to cvxpy and would be grateful for your help with the following issue. I wrote the following simple optimization code:

import cvxpy as cvx
import numpy as np

m = 4
n = 3
c = np.array([[2, 3, 0], [4, 0, 5], [2, 3, 4], [5, 0, 3]])
s = np.array([[10, 25, 18, 15]])
d = np.array([[15, 20, 16]])

X = cvx.Variable(m, n)

objective = cvx.Minimize(cvx.sum_entries(cvx.mul_elemwise(c, X)))

col_sums = cvx.sum_entries(X, axis=0)
row_sums = cvx.sum_entries(X, axis=1)

constraints = [X >= 0, col_sums <= d,
               row_sums.T == s, X[0][2]==0,
               X[1][1] == 0, X[3][1] == 0]
prob = cvx.Problem(objective, constraints)

print "Optimal value", prob.solve()
print "Optimal var"
print X.value # A numpy matrix.

Unfortunately, when I run the code, it produces the following error:

runfile('C:/Users/yavigol/Dropbox/Education/GT Optimization/W5/HW5code.py', wdir='C:/Users/yavigol/Dropbox/Education/GT Optimization/W5')
Traceback (most recent call last):

  File "<ipython-input-1-0cb639eae2e3>", line 1, in <module>
    runfile('C:/Users/yavigol/Dropbox/Education/GT Optimization/W5/HW5code.py', wdir='C:/Users/yavigol/Dropbox/Education/GT Optimization/W5')

  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
    execfile(filename, namespace)

  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "C:/Users/yavigol/Dropbox/Education/GT Optimization/W5/HW5code.py", line 41, in <module>
    col_sums = cvx.sum_entries(X, axis=0)

TypeError: __init__() got an unexpected keyword argument 'axis'

What is wrong with the code and what would be the best way to correct it? Thank you in advance!

yavigol
  • 1
  • 1

1 Answers1

0

Educated guess: you are using an outdated version of cvxpy:

This functionality was introduced in 0.3.3 (link: git blame on this source-part).

I can't see any other explanation here (using the current 1.0-dev branch would result in some other error).

sascha
  • 32,238
  • 6
  • 68
  • 110
  • sascha, thank you! I'll try to install the latest version, though the process is a little bit complicated for a non software developer like me :) python(x,y) installs the old version due to some reason unfortunately – yavigol Feb 12 '18 at 15:47
  • Anaconda is the (more) recommended way of installing. – sascha Feb 12 '18 at 15:50