MLinExpr.sum()

sum ( axis=None )

Sum the elements of this MLinExpr; returns an MLinExpr object.

Arguments:

axis: An int, or None. Sum along the specified axis. If set to None, summation takes place along all axes of this MLinExpr.

Return value:

An MLinExpr representing the sum.

Example usage:

  expr = 2 * model.addMVar((2, 2)) - 1
  sum_row = expr.sum(axis=0)  # Sum along the rows
  sum_col = expr.sum(axis=1)  # Sum along the columns
  sum_all = expr.sum()  # Sum all elements, result is 0-D