sum#

ParamDictND.sum(*pattern)[source]#

Calculate the sum of all parameter values or a subset based on wildcard pattern.

Parameters:
*patternAny, optional

For subsets, the pattern requires one value for each dimension of the N-dim tuple key. The single-character string '*' (asterisk) can be used as a wildcard to represent all possible values for a dimension.

Returns:
int or float
Raises:
StatisticsError

If the ParamDict is empty.

TypeError

If the pattern includes non-scalar(s).

ValueError

If the pattern is not the same as the length of N-dim tuple keys.

ValueError

If the pattern has no wildcard or all wildcards.

Examples

>>> demand = ParamDictND({('A', 'B'): 10, ('B', 'C'): 20, ('A', 'C'): 15, ('C', 'A'): 16})

Sum of all parameter values:

>>> demand.sum()
61

Sum of a subset based on wildcard pattern:

>>> demand.sum('A', '*')
25
>>> demand.sum('*', 'A')
16