In: Computer Science
Write the python code that generates a normal sample with given μ and σ, and the code that calculates m and s from the sample. Do the same using the Bayes’ estimator assuming a prior distribution for μ.
#source code:
import numpy as np
mue=5 #here mue value i took 5
sigma=0.1 #here i took sigma value=0.1
sample_count=100
sample=np.random.normal(mue,sigma,sample_count)
print("Sample Data Generated:\n",sample) #here ganerate sample
data
print("Mean(M value):",np.mean(sample)) #calculate the mue value
based on sample data geneated
print("Standard Deviation(S value):",np.std(sample)) #calculate the
sigma value based on sample data
#bayes:
check=lambda k:np.random.normal(5,0.1,k)
fun=check(100)
print("sample Data:\n",fun)
print("Mean",np.mean(fun))
print("Std",np.std(fun))
#output:
#if you have any doubt comment below...