0
下面是關於二項分佈隨機的程序。在這段代碼中,我不明白句子hx,xedge = np.histogram(x,xgrid)
。'hx,xedge = np.histogram(x,xgrid)'的含義'
它是做什麼的?用直方圖繪製條形圖嗎?
我做線圖使用此代碼:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rc('xtick', labelsize=12)
matplotlib.rc('ytick', labelsize=12)
#generate random number from binomial density
# with test number of 10 and probability of event of 0.4
x = np.random.binomial(10,0.4,size=1000)
print(x)
#analyze the random samples with a histogram
xgrid = np.arange(0.5,20.5,1)
xcenter = (xgrid[1:]+xgrid[0:len(xgrid)-1])/2.
hx,xedge = np.histogram(x,xgrid)
#draw the histogram
fig = plt.figure(figsize=[10,5])
ax = fig.add_subplot(111)
ax.plot(xcenter,hx,'ko-')
fig.savefig('binomrand_hist.png',bbox_inches='tight')
感謝。我知道文檔。但你的回答讓我更清楚。 –