开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜