Skip to content

Commit

Permalink
Merge pull request #84 from DerMoehre/feature/mean-np
Browse files Browse the repository at this point in the history
Closes #77
  • Loading branch information
JoFrhwld authored Oct 17, 2022
2 parents d92b87b + 1210a0e commit 677dde8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
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
]
],
[
[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

0 comments on commit 677dde8

Please sign in to comment.