X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=math_utils.py;h=dec34f049aa0382823768c53efc2060ae8c69409;hb=532df2c5b57c7517dfb3dddd8c1358fbadf8baf3;hp=156862a9c1b55eeec5515efef82f8f951d59b416;hpb=1ff5dde5b037f8da4c9d5a65e2d7ad2f6715ff60;p=python_utils.git diff --git a/math_utils.py b/math_utils.py index 156862a..dec34f0 100644 --- a/math_utils.py +++ b/math_utils.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +# © Copyright 2021-2022, Scott Gasch + """Mathematical helpers.""" import collections @@ -74,6 +76,8 @@ class NumericPopulation(object): return self.aggregate / count def get_mode(self) -> Tuple[float, int]: + """Returns the mode (most common member).""" + count: Dict[float, int] = collections.defaultdict(int) for n in self.lowers: count[-n] += 1