Filter Content By
Version
Languages

### 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