Code: Alles auswählen
import math
import scipy.stats as stats
class NormalDistribution:
def __init__(self, mu, sigma_square):
self.mu = mu
self.sigma = math.sqrt(sigma_square)
def pdf(self, x):
return 1 / (self.sigma * math.sqrt(2 * math.pi)) * math.exp(-(math.pow(x - self.mu, 2) / (2 * math.pow(self.sigma, 2))))
print(NormalDistribution(0, 3).pdf(1))
print(stats.norm.pdf(1, 0, 3))
Code: Alles auswählen
Output:
0.19496965572274114 # Ausgabe des Programms
0.12579440923099774 # Korrekte Ausgabe
LG nono