labm8.math¶
Math utils. Import as “labmath” to prevent conflicts with system math package.
-
labm8.math.
ceil
(number)¶ Return the ceiling of a number as an int.
This is the smallest integral value >= number.
Example
>>> labmath.ceil(1.5) 2
Parameters: number (float) – A numeric value. Returns: Smallest integer >= number. Return type: int Raises: TypeError
– If argument is not a numeric value.
-
labm8.math.
confinterval
(array, conf=0.95, normal_threshold=30, error_only=False, array_mean=None)¶ Return the confidence interval of a list for a given confidence.
Parameters: - array (list) – Sequence of numbers.
- conf (float) – Confidence interval, in range 0 <= ci <= 1
- normal_threshold (int) – The number of elements in the array is < normal_threshold, use a T-distribution. If the number of elements in the array is >= normal_threshold, use a normal distribution.
- error_only (bool, optional) – If true, return only the size of symmetrical confidence interval, equal to ci_upper - mean.
- array_mean (float, optional) – Optimisation trick for if you already know the arithmetic mean of the array to prevent this function from re-calculating.
Returns: - Lower and upper bounds on confidence interval,
respectively.
Return type: (float, float)
-
labm8.math.
filter_iqr
(array, lower, upper)¶ Return elements which falls within specified interquartile range.
Parameters: - array (list) – Sequence of numbers.
- lower (float) – Lower bound for IQR, in range 0 <= lower <= 1.
- upper (float) – Upper bound for IQR, in range 0 <= upper <= 1.
Returns: - Copy of original list, with elements outside of IQR
removed.
Return type: list
-
labm8.math.
floor
(number)¶ Return the floor of a number as an int.
This is the largest integral value <= number.
Example
>>> labmath.floor(1.5) 1
Parameters: number (float) – A numeric value. Returns: Largest integer <= number. Return type: int Raises: TypeError
– If argument is not a numeric value.
-
labm8.math.
geomean
(array)¶ Return the mean value of a list of divisible numbers.
-
labm8.math.
iqr
(array, lower, upper)¶ Return interquartile range for given array.
Parameters: - lower (float) – Lower bound for IQR, in range 0 <= lower <= 1.
- upper (float) – Upper bound for IQR, in range 0 <= upper <= 1.
Returns: Lower and upper IQR values.
Return type: (float, float)
-
labm8.math.
mean
(array)¶ Return the mean value of a list of divisible numbers.
-
labm8.math.
median
(array)¶ Return the median value of a list of numbers.
-
labm8.math.
range
(array)¶ Return the range between min and max values.
-
labm8.math.
sqrt
(number)¶ Return the square root of a number.
-
labm8.math.
stdev
(array)¶ Return the standard deviation of a list of divisible numbers.
-
labm8.math.
variance
(array)¶ Return the variance of a list of divisible numbers.