sum ( axis=None )

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


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

Return value:

An MQuadExpr representing the sum.

Example usage:

  expr = 2 * model.addMVar((2, 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