1

基本的に、いくつかの 2D ヒストグラムを一緒に追加する必要がありますが、これを行う方法がわかりません。単一のヒストグラムに対してそれを行う前に、私はこのようにしました...

enter for i in range(0,BMI[ind_2008].shape[0]):

id_temp=ID[ind_2008[i]]     
ind_2009_temp=np.where(ID[ind_2009] == id_temp)
actual_diff=BMI[ind_2008[i]]-BMI[ind_2009[ind_2009_temp]]
diff=np.abs(BMI[ind_2008][i]-BMI_p1)
pdf_t, bins_t=np.histogram(diff,bins=range_v-1,range=(0,range_v))
if i == 0:
    pdf=pdf_t
    pdf[:]=0.0
pdf=pdf+pdf_t

bincenters = 0.5*(bins_t[1:]+bins_t[:-1])
fig3=plt.figure()
plt.plot(bincenters,pdf)

Heres は、2 次元ヒストグラム用のコードです。

for i in range(0,BMI[ind_2008].shape[0]):
    diff_BMI=np.abs(BMI[ind_2008][i]-BMI_p1)
    diff_DOB=np.abs(dob_j[ind_2008][i]-dob_jwp1)
    hist=np.histogram2d(diff_BMI,diff_DOB,bins=(35,1000))
    if i == 0:
        pdf=hist
        pdf[:]=0.0
        pdf=pdf+hist
fig3=plt.figure()
plt.plot(pdf)

コードが現時点であるため、「タプルオブジェクトはアイテムの割り当てをサポートしていません」というエラーメッセージが表示されます。エラーメッセージの意味は理解できますが、修正方法がわかりません。どんな助けでも大歓迎です...

4

1 に答える 1

1

このhistogram2d関数はトリプルを返します。

H : ndarray, shape(nx, ny)
    The bi-dimensional histogram of samples `x` and `y`. Values in `x`
    are histogrammed along the first dimension and values in `y` are
    histogrammed along the second dimension.
xedges : ndarray, shape(nx,)
    The bin edges along the first dimension.
yedges : ndarray, shape(ny,)
    The bin edges along the second dimension.

したがって、関数呼び出しは次のようになります。

H, xedges, yedges = np.histogram2d(diff_BMI, diff_DOB, bins=(35,1000))

そして、ヒストグラムで操作を行うことができますH。ただし、関数の場合のように、これは 1 次元配列ではなく、2 次元配列であることに注意してnp.histogramください。

于 2013-08-29T10:20:39.243 に答える