linopy.expressions.LinearExpression.has_terms#
- property LinearExpression.has_terms#
Get a boolean array which is true at slots with at least one live term.
A term is live when it references a variable (
vars != -1). Slots without any live term arise from outer joins inmerge, from reindexing past the original coordinates, or from masking. In contrast toisnull(), the constant is ignored: a slot carrying only a constant has no terms.- Returns:
xr.DataArray
Examples
Mask out constraint rows whose left-hand side has no terms:
>>> import linopy >>> import pandas as pd >>> m = linopy.Model() >>> x = m.add_variables(coords=[pd.RangeIndex(3, name="i")], name="x") >>> lhs = (1 * x).reindex(i=pd.RangeIndex(5, name="i")) >>> lhs.has_terms.values array([ True, True, True, False, False])