Try our new documentation site (beta).


MVar.diagonal()

diagonal ( offset=0, axis1=0, axis2=1 )

Create an MVar corresponding to the variables on the specified diagonal of this MVar.

Arguments:

offset (optional): Offset of the diagonal w.r.t. the main diagonal. Values >0 mean above it, and values <0 below it

axis1 (optional): Axis to be used as the first axis of the 2-D sub-MVar from which the diagonal should be taken. Defaults to 0. You need to consider this argument only for MVar objects with more than 2 dimensions.

axis2 (optional): Axis to be used as the second axis of the 2-D sub-MVar from which the diagonal should be taken. Defaults to 1. You need to consider this argument only for MVar objects with more than 2 dimensions.

Return value:

An MVar representing the requested diagonal of this MVar.

Example usage:

  x = model.addMVar((8, 8))
  diag_main = x.diagonal()  # The main diagonal of x
  diag_sup = x.diagonal(1)  # The first superdiagonal of x
  diag_sup = x.diagonal(-2)  # The second subdiagonal of x
  adiag_main = x[:, ::-1].diagonal()  # The main anti-diagonal of x

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.

Search

Gurobi Optimization