linopy.constraints.Constraints.to_matrix

linopy.constraints.Constraints.to_matrix#

Constraints.to_matrix()#

Construct a constraint matrix in sparse format by stacking per-constraint CSR matrices.

Each per-constraint CSR has active constraint rows only and dense variable positions as column indices. Shape is (n_active_cons, n_active_vars).

Returns:

  • matrix (scipy.sparse.csr_array) – Shape (n_active_cons, n_active_vars).

  • con_labels (np.ndarray) – Shape (n_active_cons,), maps each matrix row to the original constraint label.