Try our new documentation site (beta).

prod ( coeff, pattern )

Returns a linear expression that contains one term for each tuple that is present in both the tupledict and in the argument dict. For example, would contain term <span>$</span>2.0*var<span>$</span> if x[1,2] = var and coeff[1,2] = 2.0.


coeff: Python dict that maps tuples to coefficients.

pattern: Pattern to match for a key tuple.

Example usage:

  x = m.addVars([(1,2), (1,3), (2,3)])
  coeff = dict([((1,2), 2.0), ((1,3), 2.1), ((2,3), 3.3)])
  expr = # LinExpr: 2.0 x[1,2] + 2.1 x[1,3] + 3.3 x[2,3]
  expr =, '*', 3) # LinExpr: 2.1 x[1,3] + 3.3 x[2,3]

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.