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