blade.xmath¶
blade mathing operations.
- blade.xmath.xaverage(iterable)¶
Discover average value of numbers in iterable.
Parameters: iterable – iterable object Returns: a number >>> from blade.xmath import xaverage >>> xaverage([10, 40, 45]) 31.666666666666668
- blade.xmath.xcount(iterable)¶
Discover how common each item in iterable is and the overall count of each item in iterable.
Parameters: iterable – iterable object Returns: Collects namedtuple Count(least=int, most=int, overall=[(thing1, int), (thing2, int), ...]) >>> from blade.xmath import xcount >>> common = xcount([11, 3, 5, 11, 7, 3, 5, 11]) >>> # least common thing >>> common.least 7 >>> # most common thing >>> common.most 11 >>> # total count for every thing >>> common.overall [(11, 3), (3, 2), (5, 2), (7, 1)]
- blade.xmath.xinterval(iterable)¶
Discover the length of the smallest interval that can contain the value of every items in iterable.
Parameters: iterable – iterable object Returns: a number >>> from blade.xmath import xinterval >>> xinterval([3, 5, 7, 3, 11]) 8
- blade.xmath.xmedian(iterable)¶
Discover median value of numbers in iterable.
Parameters: iterable – iterable object Returns: a number >>> from blade.xmath import xmedian >>> xmedian([4, 5, 7, 2, 1]) 4 >>> xmedian([4, 5, 7, 2, 1, 8]) 4.5
- blade.xmath.xminmax(iterable)¶
Discover the minimum and maximum values among items in iterable.
Parameters: iterable – iterable object Returns: namedtuple MinMAx(min=value, max=value). >>> from blade.xmath import xminmax >>> minmax = xminmax([1, 2, 4]) >>> minmax.min 1 >>> minmax.max 4
- blade.xmath.xsum(iterable, start=0, precision=False)¶
Discover the total value of adding start and items in iterable together.
Parameters: >>> from blade.xmath import xsum >>> # default behavior >>> xsum([1, 2, 3]) 6 >>> # with a starting mumber >>> xsum([1, 2, 3], start=1) 7 >>> # add floating points with extended precision >>> xsum([.1, .1, .1, .1, .1, .1, .1, .1], precision=True) 0.8