Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mean_stdv ignores None element in list (extractFormants.py) #84

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions fave/extractFormants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,20 +1068,14 @@ def maximumIntensity(intensities, times):
def mean_stdv(valuelist):
"""returns the arithmetic mean and sample standard deviation (N-1 in the denominator) of a list of values"""

n = len(valuelist)
if n > 0:
if n == 1:
np_valuelist = np.array(valuelist,dtype=np.float64)
if len(np_valuelist) > 0:
if len(np_valuelist) == 1:
mean = valuelist[0]
stdv = 0
else:
sum_i = 0
for i in range(n):
sum_i += valuelist[i]
mean = sum_i / n
diffsum_i = 0
for i in range(n):
diffsum_i += (valuelist[i] - mean) ** 2
stdv = math.sqrt(diffsum_i / (n - 1))
mean = np.nanmean(np_valuelist)
stdv = np.nanstd(np_valuelist, ddof=1)

else: # empty list
mean = None
Expand Down
3 changes: 2 additions & 1 deletion tests/fave/extract/test_extractFormants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from cmath import nan
import logging
import pytest
import numpy as np
Expand Down Expand Up @@ -42,7 +43,7 @@ def provide_valuelist():
[-1],
np.mean([-1]),
0
]
],
JoFrhwld marked this conversation as resolved.
Show resolved Hide resolved
[
[3.5, 2.6, 11.6, None, 34.66, 2.8, 4.7],
np.nanmean(np.array([3.5, 2.6, 11.6, None, 34.66, 2.8, 4.7],
Expand Down