Based on my previous question here: How to filter a stream of data
I have encountered an error with the following code:
def alpha_mean(window, alpha):
cut = alpha//2
data = sorted(window)[cut:-cut]
result = sum(data)/len(data)
return result
def alphatrimmer(window_size, alpha, sensor_stream):
window = []
for item in sensor_stream:
window.append(item)
if len(window) >= window_size:
break
yield alpha_mean(window, alpha)
for item in sensor_stream:
window.pop(0)
window.append(item)
yield alpha_mean(window,alpha)
The output is a "generator object at 0x00000078' and when I try to iterate it over the generator object, I get an error that float cannot be iterated over. The problem is that I pass the input as floats. How do I fix the issue where floats passed in the generator can be iterated over and printed out? Thank you.
User contributions licensed under CC BY-SA 3.0