ParamDictND#
- class ParamDictND(mapping=None, /, *, key_names=None, value_name=None)[source]#
Custom subclass of dict to define parameters with N-dim tuple keys.
Requires all keys to be unique tuples of the same length, each containing ‘N’ scalars (such as int, str, pd.Timestamp, etc.) and all values to be int or float.
- Parameters:
- mappingdict or dict-like mapping, optional
Input data to be encapsulated in the ParamDict.
- key_namessequence[str], optional
Names to refer to each dimension of N-dim tuple keys - not used internally but solely for user reference.
- value_namestr, optional
Name to refer to parameter values - not used internally, and solely for user reference.
- Raises:
- TypeError
If input includes key(s) that are not tuples.
- ValueError
If input includes tuple keys of different lengths.
- TypeError
If input includes values that are not int or float.
See also
ParamDict1DFor 1-dim scalar keys.
Examples
Constructing empty to populate later:
>>> ParamDictND() ParamDictND: {}
Constructing with a mapping:
>>> ParamDictND( ... {('A', 'B'): 10, ('B', 'C'): 20, ('A', 'C'): 15}, ... key_names=('ORI', 'DES'), ... value_name='DEMAND', ... ) ParamDictND: (ORI, DES) -> DEMAND {('A', 'B'): 10, ('B', 'C'): 20, ('A', 'C'): 15}
Methods
Remove all items from the ParamDict.
ParamDictND.get(key[, default])Get the parameter value for the specified key, or the default if not found.
ParamDictND.lookup(*key)Get the parameter value for the specified key, or zero if it is not found.
ParamDictND.max(*pattern)Calculate the maximum of all parameter values or a subset based on wildcard pattern.
ParamDictND.mean(*pattern)Calculate the mean of all parameter values or a subset based on wildcard pattern.
ParamDictND.median(*pattern)Calculate the median of all parameter values or a subset based on wildcard pattern.
ParamDictND.median_high(*pattern)Calculate the high median of all parameter values or a subset based on wildcard pattern.
ParamDictND.median_low(*pattern)Calculate the low median of all parameter values or a subset based on wildcard pattern.
ParamDictND.min(*pattern)Calculate the minimum of all parameter values or a subset based on wildcard pattern.
ParamDictND.pop(key[, default])Remove the specified key and return it's parameter value, or the default if not found.
Remove and return the last inserted key and parameter value pair from the ParamDict.
ParamDictND.setdefault(key, default, /)Get the parameter value for the specified key, or the default if not found.
ParamDictND.subset_keys(*pattern)Get a subset of the N-dim tuple keys of the Dict with a wildcard pattern.
ParamDictND.subset_values(*pattern)Get Dict values for all keys that match the wildcard pattern.
ParamDictND.sum(*pattern)Calculate the sum of all parameter values or a subset based on wildcard pattern.
Attributes
Names to refer to each dimension of N-dim tuple keys.
Name to refer to Dict values.