Operations on 2D MVar objects work natively, following the dimensionality conventions of numpy. For example, let \( a \in \mathbb{R}^m \), let \(b \in \mathbb{R}^n \), and let \(X\) be an \( m \times n \) MVar object. We can model the expression \( a^\top X b \) as follows:
import gurobipy as gp
import numpy as np
model = gp.Model()
X = model.addMVar((3,4))
a = np.random.rand(3)
b = np.random.rand(4)
model.setObjective(a @ X @ b)
Further information
- How do I multiply two MLinExpr objects together with the matrix-friendly Python API?
- How do I pointwise multiply a numpy vector with a (1,) MVar with the matrix-friendly Python API?
- How do I pointwise multiply two MVars with the matrix-friendly Python API?
- How do I pointwise multiply an array and an MVar with the matrix-friendly Python API?
Comments
0 comments
Article is closed for comments.