PyROOT:Fill histogram from two numpy array

Dear Experts,

I want to make correlation plot(TH2) from two numpy array.
I tried as below but it is too slow and I don’t know how use multi-threading in python… any idea to make more faster?

Best regards,
Kyounghyoun

code:
for i in range(len(img1.flatten())):
for j in range(len(img2.flatten())):
hist.Fill(img1.flatten()[i],img2.flatten()[j])

Maybe @etejedor can give you some hints

1 Like

Dear bellenot
I solve this problem with np.histogram2d as below.

scatter,x_edge,y_edge = np.histogram2d(img1.flatten(),img2.flatten(),bins=(x_edge,y_edge))

for i in range(scatter.shape[0]):
for j in range(scatter.shape[1]):
hist.Fill(i,j,scatter[i,j])
where each edges mean binning and scatter is matrix

thank you

1 Like

Thank you for sharing!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.