Suppose we want to add the following constraint to our model, which involves the pointwise multiplication of a 1-D ndarray with a 1-D MVar of length one:

$$\begin{align} \begin{bmatrix} y_1 \\ y_2 \\ y_3 \end{bmatrix} &= \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix} x. \end{align}$$

The following code results in a `TypeError`:

import gurobipy as gp

import numpy as np

m = gp.Model()

x = m.addMVar(1)

y = m.addMVar(3)

m.addConstr(y == np.ones(3) * x) # error!

Instead, one can recast this operation as a matrix-vector product:

import gurobipy as gp

import numpy as np

m = gp.Model()

x = m.addMVar(1)

y = m.addMVar(3)

m.addConstr(y == np.ones((3, 1)) @ x)

The first version of the Python matrix API was included in the release of Gurobi 9.0. The developers are continually working on behavior like this to improve the usability of the matrix API.

### Further information