每次运行代码时,情节看起来都不同
我的代码有问题。每次运行时,它看起来都不同。有什么想法吗?我看不到任何问题。我从2H开始查看此代码,但找不到问题...
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
x = np.arange(0,24, 1)
y = stats.poisson.pmf(x, mu=13)
a =stats.poisson.rvs(mu=13, size=5000)
#plt.stem(a,x)
plt.hist(a,bins=x,density=True,edgecolor="red")
plt.title("Poisson Verteilung mit Erwartungswert 13")
plt.xlabel("Anzahl M.")
plt.ylabel("Wahrscheinlichkeit")
"""
i=10
o=30
while i != o:
if y[i]*100<0.5:
#print(i)
break
i+=1
"""
#plot to specific x value
plt.xlim(0, 23)
plt.plot()
plt.plot(13, y[13], marker='x', markersize=5, color="black",label="Varianz")
plt.plot(13, y[13], marker='x', markersize=5, color="black",label="Median")
plt.legend(loc="upper left")
I have a problem with my code. It looks different everytime i run it. Any ideas? I don't see any problem. I am looking at this code since 2h and I can't find the problem...
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
x = np.arange(0,24, 1)
y = stats.poisson.pmf(x, mu=13)
a =stats.poisson.rvs(mu=13, size=5000)
#plt.stem(a,x)
plt.hist(a,bins=x,density=True,edgecolor="red")
plt.title("Poisson Verteilung mit Erwartungswert 13")
plt.xlabel("Anzahl M.")
plt.ylabel("Wahrscheinlichkeit")
"""
i=10
o=30
while i != o:
if y[i]*100<0.5:
#print(i)
break
i+=1
"""
#plot to specific x value
plt.xlim(0, 23)
plt.plot()
plt.plot(13, y[13], marker='x', markersize=5, color="black",label="Varianz")
plt.plot(13, y[13], marker='x', markersize=5, color="black",label="Median")
plt.legend(loc="upper left")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用随机统计分发,每次运行代码a时创建了新的随机分布。
为了获得可重复性(运行时,您的代码选择始终是相同的随机分发),您必须
完整的代码
图
You are using random statistical distribution, each time you run your code a new random distribution is created.
In order to get repeatability (your code picks always the same random distribution when you run it) you have to set a seed at the beginning of your code:
You can choose which seed you prefer, 42 is a common one.
Complete Code
Plot