I am trying to create a function to calculate the moving average on a set of data. This is the function:
def averaged_rel_track(navg, rel_values, nb, zeroindex):
#function to average the relative track values for each blade. This is
#dependant on the number values specified by the user to average over in a
#rolling average
for blade in range(0,int(nb)):
av_values=[]
rel_blade=rel_values[:,blade]
for rev in range(0,len(rel_blade)):
section=rel_blade[rev-int(navg)+1:rev]
av_value=np.mean(section)
av_values.append(av_value)
print av_values
however I would like to add a check to it and I'm strugging witht the best way to implement this...
If the number of averages (navg) in the moving average is say 24 the average is taken of the 23 values before the specified element and the element. However, if one of those 24 values is a zero I want the average for that specified element to be zero. I tried:
def averaged_rel_track(navg, rel_values, nb, zeroindex):
#function to average the relative track values for each blade. This is
#dependant on the number values specified by the user to average over in a
#rolling average
for blade in range(0,int(nb)):
av_values=[]
rel_blade=rel_values[:,blade]
for rev in range(0,len(rel_blade)):
section=rel_blade[rev-int(navg)+1:rev]
av_value=np.mean(section)
zero_test= np.where(np.any(section==0))
print zero_test
if len(zero_test)==0:
av_value=None
av_values.append(av_value)
print av_values
However the length of zero_test is always 1?
Can anyone think of a way to correct this method or a different method altogether?
Cheers