Created
April 23, 2021 00:22
-
-
Save euikook/888f2f8c1a7226995cae998e83eb9239 to your computer and use it in GitHub Desktop.
Average Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def avg_batch(v): | |
return sum(v)/len(v) | |
def avg_recursive(a, v, n): | |
return n/(n + 1)*a + v/(n+1) | |
if __name__ == '__main__': | |
ages = [10, 12, 26, 30, 40, 33, 21, 34, 54, 3] | |
print(f'Average using Batch Expression: {avg_batch(ages)}') | |
avg = 0 | |
for idx in range(len(ages)): | |
avg = avg_recursive(avg, ages[idx], idx) | |
print(f'Average using Recursive Expression: {avg}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment