reshape ( shape, order='C' )

Return a copy of this MVar with the same variables, but with a new shape.


shape: An int, or a tuple of int. The new shape should be compatible with this MVar's shape. The special value of -1 can be passed in at one position, which then infers the length of that dimension from the overall number of Var objects in the MVar and the provided lengths of the other dimensions.

order (optional): A string 'C' or 'F'. Read the elements of this MVar using C-like ('C') or Fortran-like ('F') order, and write the elements into the reshaped array in this order.

Return value:

An MVar of requested shape

Example usage:

  x = model.addMVar((2, 2))
  x_vec = x.reshape(-1, order='C')  # 1-D result, rows of x stacked
  x_vec = x.reshape(-1, order='F')  # 1-D result, columns of x stacked

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.