-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Add geometric_mean.py #4244
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
Add geometric_mean.py #4244
Conversation
maths/series/geometric_mean.py
Outdated
""" | ||
if len(series) == 1: | ||
return True | ||
common_ratio = series[1] / series[0] |
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.
Will fail with empty series.
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.
Also if series[0] is 0 will fail as well
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.
Will fail with empty series.
for that I have check the size of list. If it is zero then It will raise an error.
if len(series) == 0:
raise ValueError("Input list must be a non empty list")
Would it be fine or ... how can I do it in a better way ?
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.
Right, didn't notice.
maths/series/geometric_mean.py
Outdated
raise ValueError("Input list is not a geometric series") | ||
answer = 1 | ||
for _ in series: | ||
answer *= _ |
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.
I don't like it named _
. _
means that it's not important but actually it's affecting answer
variable.
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.
I don't like it named
_
._
means that it's not important but actually it's affectinganswer
variable.
sorry for this silly mistake.
@@ -0,0 +1,55 @@ | |||
def is_geometric_series(series: list) -> bool: |
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.
Please add link with some theory about algorithm.
This reverts commit 11792ec.
@mateuszz0000 , I tried to resolve all the mistakes. I know you all guys are also busy, so if you get some time, then please review this PR . |
* geometric_mean3 * update-GM.PY * update-AM.PY * Revert "update-AM.PY" This reverts commit 11792ec.
* geometric_mean3 * update-GM.PY * update-AM.PY * Revert "update-AM.PY" This reverts commit 11792ec.
* geometric_mean3 * update-GM.PY * update-AM.PY * Revert "update-AM.PY" This reverts commit 11792ec.
Describe your change:
Added an algorithm to compute the geometric mean of series
Checklist:
Fixes: #{$ISSUE_NO}
.