Suppose we want to add the following constraint to our model, which involves the pointwise multiplication of two MVar objects:

$$\begin{align} \begin{bmatrix} u_1 \\ u_2 \\ u_3 \end{bmatrix} = \begin{bmatrix} x_1 y_1 \\ x_2 y_2 \\ x_3 y_3 \end{bmatrix}. \end{align}$$

The following code results in a `float() argument must be a string or a number, not 'MVar'` TypeError:

import gurobipy as gp

import numpy as np

m = gp.Model()

x = m.addMVar(3)

y = m.addMVar(3)

u = m.addMVar(3)

m.addConstr(u == x * y) # error!

Instead, we can add these constraints row-by-row. For example:

import gurobipy as gp

import numpy as np

m = gp.Model()

x = m.addMVar(3)

y = m.addMVar(3)

u = m.addMVar(3)

m.addConstrs(u[i] == x[i] @ y[i] for i in range(3))

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