title: Data Envelopment Analysis implementation in Python Gurobi
body: <p><a href="https://i.stack.imgur.com/f1BEX.jpg" rel="nofollow noreferrer">Attached is the DEA notes</a></p>
  
  <p>Below is the code I am having so far. When I run it, I got this error 
  line 33, in 
      m.addConstr(quicksum([L[i]<em>Xi[i][j] for j in range(n1) if i &lt;= j])-(theta</em>X0[k][j] for j in range(len(Xi))) &lt;= 0,'Xi%d' % (i))</p>
  
  <p>File "linexpr.pxi", line 429, in gurobipy.LinExpr.<strong>sub</strong> (../../src/python/gurobipy.c:32250)</p>
  
  <p>TypeError: unsupported operand type(s) for *: 'int' and 'generator'</p>
  
  <pre><code>from gurobipy import *
  
  X0 =[[5,14],\
      [8,15],\
      [7,12]]
  
  Xi = list(map(list, zip(*X0)))
  
  Y0 =[[9,4,16],\
      [5,7,10],\
      [4,9,13]]
  
  Yi = list(map(list, zip(*Y0)))    
  
  n1= len(X0)
  n2= len(Yi)
  
  m = Model("DEA")
  
  #set up variables
  theta = m.addVar(obj=1)#,vtype=GRB.SEMIINT,name='theta')
  
  L = {}
  for i in range(n1):
      L[i] = m.addVar(obj=0,vtype=GRB.SEMIINT, lb=0,name='L%d' % i)
  
  m.update() 
  
  #set up constraints
  k = 0
  for i in range(n1):
      m.addConstr(quicksum([L[i]*Xi[i][j] for j in range(n1) if i &lt;= j])-(theta*X0[k][j] for j in range(len(Xi))) &lt;= 0,'Xi%d' % (i))
  
  for i in range(n2):
      m.addConstr(quicksum([L[i]*Yi[i][j] for j in range(n1) if i &lt;= j]) &gt;= Y0[k][i], 'Yi%d' % (i))
  
  m.optimize()
  
  m.write('DEA.lp')
  
  # Print solution
  if m.status == GRB.status.OPTIMAL:
      print ('\nOptimal flows:')
      for v in m.getVars():
          if v.X &gt; 0:
              print( '%6s = %4.1f' % (v.VarName, v.X))
      print()
      print( 'Objective Value:', m.ObjVal)
  
  else:
      print ('Bummer ',m.status)
  </code></pre>