Multidimension histogram in python
I have a multidimensional histogram
H=histogramdd((x,y,z),bins=(nbins,nbins,nbins),range=((0,1),(0,1),(0,1)))
I need to print in an array the values of H which are different from zero and I also开发者_如何学Python need to know the coordinate/the bins where this happens.
I am not familiar with tuples. Can you help me?
use where to find the index of nozeros in H, and use the index to get the coordinate:
import numpy as np
x = np.random.random(1000)
y = np.random.random(1000)
z = np.random.random(1000)
nbins = 10
H, [bx, by, bz]=np.histogramdd((x,y,z),bins=(nbins,nbins,nbins),range=((0,1),(0,1),(0,1)))
ix, iy, iz = np.where(H)
for t in zip(bx[ix], by[iy], bz[iz], H[ix,iy,iz]):
print t
精彩评论