Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" chemreac.util.pyutil --------------------
Utility functions used throughout chemreac.
"""
""" Check monotonicity of a serie
Parameters ---------- arr: array_like Array to be checked for monotonicity positive: -1, 0 or 1 (default: 0) -1: negative, 1: positive, 0: either strict: bool (default: False) Disallow zero difference between neighboring instances
Examples -------- >>> monotonic([0, 0, -1, -2]) True >>> monotonic([0, 0, 1, 2], strict=True) False >>> monotonic([1, 2, 3], -1) False
Returns ------- bool """ raise ValueError("positive should be either -1, 0 or 1") else: else:
""" Modifies a dictionary in-place by populating key/value pairs present in the default dictionaries which have no key in original dictionary `dct`. Useful for passing along keyword argument dictionaries between functions.
Parameters ---------- dct: dict *args: dictionaries
Returns ------- dct: (possibly modified) input dictionary
Examples -------- >>> d = {1: None} >>> set_dict_defaults_inplace(d, {2: []}) >>> d == {1: None, 2: []} True >>> f = {'a': 1, 'b': 3} >>> g = {'a': 1} >>> set_dict_defaults_inplace(g, {'b': 2, 'a': 7}, {'b': 3}) >>> f == g True >>> h = {42: True, 'b': 3} >>> i = {} >>> set_dict_defaults_inplace(i, {42: True, 'b': 2}, {'b': 3}) >>> h == i True """ |