Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions maths/gaussian.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""
Reference: https://en.wikipedia.org/wiki/Gaussian_function

python/black : True
python : 3.7.3

"""
from numpy import exp, pi, sqrt

Expand All @@ -16,6 +12,12 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
>>> gaussian(24)
3.342714441794458e-126

>>> gaussian(1, 4, 2)
0.06475879783294587

>>> gaussian(1, 5, 3)
0.05467002489199788

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See?

Supports NumPy Arrays
Use numpy.meshgrid with this to generate gaussian blur on images.
>>> import numpy as np
Expand Down Expand Up @@ -49,8 +51,8 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:

>>> gaussian(2523, mu=234234, sigma=3425)
0.0
"""
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-((x - mu) ** 2) / 2 * sigma ** 2)
"""
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-((x - mu) ** 2) / (2 * sigma ** 2))


if __name__ == "__main__":
Expand Down