Multidimension histogram in python

浪子不回头ぞ 提交于 2019-12-09 22:34:54

问题


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 need to know the coordinate/the bins where this happens.

I am not familiar with tuples. Can you help me?


回答1:


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


来源:https://stackoverflow.com/questions/6909247/multidimension-histogram-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!