It is not currently possible to multiply two MLinExpr objects together to create an MQuadExpr object. For example, consider the following constraint:

$$\begin{align} y &= (Ax + b)^\top (Ax + b). \end{align}$$

The following code results in a `Cannot multiply with an MLinExpr from the left` GurobiError:

import gurobipy as gp

import numpy as np

m = gp.Model()

x = m.addMVar(3)

y = m.addMVar(1)

A = np.random.rand(4,3)

b = np.random.rand(4)

m.addConstr(y == (A @ x + b) @ (A @ x + b)) # error!

Instead, define the auxiliary MVar \( z \) to equal to \( A x + b \). and set \( y \) equal to the inner product \( z^\top z \):

import gurobipy as gp

import numpy as np

m = gp.Model()

x = m.addMVar(3)

y = m.addMVar(1)

z = m.addMVar(4)

A = np.random.rand(4,3)

b = np.random.rand(4)

m.addConstr(z == A @ x + b)

m.addConstr(y == z @ z)

**Note:** Gurobi 9.0 introduced the first version of the Python matrix API. The developers are continually working to improve the usability of the matrix API.