-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Average welford #6077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Average welford #6077
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
00c22a3
Added censor function
meg-1 4194344
Added censor code
meg-1 e7d4102
Added comments to the code
meg-1 93bd4ac
modified censor function
meg-1 b714278
added decrypt function
meg-1 c879c7f
added cypher and decypher functions, deleted censor and decrypt funct…
meg-1 e60dd6f
Deleted decrypt.py
meg-1 b3e0cb8
Deleted censor.py
meg-1 e14b9ef
Merge branch 'TheAlgorithms:master' into master
meg-1 947f7d8
edited the crypt and decrypt files
meg-1 daf21ad
Update cypher_txt.py
meg-1 d3d8b29
Remove the endline in cypher.py
meg-1 752c197
Removed the print at the end of decypher.py
meg-1 9f44028
comitting changes
meg-1 f72431b
added 4 new algorithms
meg-1 4c891f4
added tests to the four files
meg-1 c600b10
added type hints for the function variables
meg-1 4286e40
Merge branch 'TheAlgorithms:master' into master
meg-1 7a909e2
Deleted decode message
meg-1 f5b5411
Deleted code message
meg-1 bc8388c
Welford average algorithm
meg-1 9be479e
added average welford algorithm
meg-1 5ebf785
indentation added
meg-1 0570692
switched print to return in the end
meg-1 8e0e14e
removed average welford for a seperate pr
meg-1 bb09bfc
added average wellford
meg-1 076a37e
deleted the decrypt.py file.
meg-1 2d74975
deleted censor.py [ got into the wrong pr ]
meg-1 9bbfd9b
fixed errors with tests
meg-1 74f3905
deleted the space
meg-1 ede2b3c
deleted spaces
meg-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def average_welford(values: list) -> float: | ||
""" | ||
>>> average_welford([1, 2, 3, 4, 5]) | ||
3.0 | ||
>>> average_welford([1.2329435, 2.209462409, 3.230925, 4.47626462, 5.2938759204]) | ||
3.2886942898799996 | ||
>>> average_welford([-57386462.2329435, 2246262.209462409, 4632463.230925, 856737354.47626462, -243664265.2938759204]) | ||
112513070.4779665 | ||
""" | ||
avg = 0.0 | ||
"""while looping through the list, | ||
we calculate the average of the | ||
current element and the average | ||
of the elements before it""" | ||
for index in range(0, len(values)): | ||
avg += (values[index]-avg)/(index+1) | ||
return avg | ||
|
||
if __name__ == "__main__": | ||
import doctest | ||
doctest.testmod() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An error occured while parsing the file:
maths/average_welford.py