The docstring should explain in which situations the function will return 0, 0 as a result, i.e. which inputs for values_list will lead to this.
Originally posted by @ehrenfeu in #49 (comment)
|
def calculate_mean_and_stdv(values_list, round_decimals=0): |
|
"""Calculate mean and standard deviation from a list of floats. |
|
|
|
Parameters |
|
---------- |
|
values_list : list of int,float |
|
List containing numbers. |
|
round_decimals : int, optional |
|
Rounding decimal to use for the result, by default 0 |
|
|
|
Returns |
|
------- |
|
tuple of (float, float) |
|
Mean and standard deviation of the input list. |
|
""" |
|
filtered_list = [x for x in values_list if x is not None] |
|
|
|
if not filtered_list: |
|
return 0, 0 |
|
|
|
mean = round(sum(filtered_list) / len(filtered_list), round_decimals) |
|
variance = sum((x - mean) ** 2 for x in filtered_list) / len(filtered_list) |
|
std_dev = round(variance ** 0.5, round_decimals) |
|
|
|
return mean, std_dev |
The docstring should explain in which situations the function will return
0, 0as a result, i.e. which inputs forvalues_listwill lead to this.Originally posted by @ehrenfeu in #49 (comment)
python-imcflibs/src/imcflibs/imagej/misc.py
Lines 104 to 128 in f0a1c9c