Skip to content

Commit

Permalink
changed mean_stdv() to numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
DerMoehre authored and chrisbrickhouse committed Mar 13, 2024
1 parent f19293b commit 6049041
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
24 changes: 5 additions & 19 deletions fave/extractFormants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,28 +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)
empty = 0
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):
if valuelist[i] == None:
empty += 1
continue
else:
sum_i += valuelist[i]
mean = sum_i / (n - empty)
diffsum_i = 0
for i in range(n):
if valuelist[i] == None:
continue
else:
diffsum_i += (valuelist[i] - mean) ** 2
stdv = math.sqrt(diffsum_i / ((n - empty) - 1))
mean = np.nanmean(np_valuelist)
stdv = np.nanstd(np_valuelist, ddof=1)

else: # empty list
mean = None
Expand Down
1 change: 1 addition & 0 deletions 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

0 comments on commit 6049041

Please sign in to comment.