mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
Correcting the Gaussian Formula (#2249)
* Correcting the Gaussian Formula I have added the parenthesis around the 2*sigma^2 term. * Update gaussian.py * Update gaussian.py * Update gaussian.py * Update gaussian.py * Update gaussian.py * Update gaussian.py Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
c7a5f1673e
commit
373f193c6d
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
Supports NumPy Arrays
|
||||
Use numpy.meshgrid with this to generate gaussian blur on images.
|
||||
>>> import numpy as np
|
||||
|
@ -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__":
|
||||
|
|
Loading…
Reference in New Issue
Block a user