Python中的多维直方图 [英] Multidimension histogram in python

查看:283
本文介绍了Python中的多维直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多维直方图

   H=histogramdd((x,y,z),bins=(nbins,nbins,nbins),range=((0,1),(0,1),(0,1)))

我需要在数组中打印不同于零的H值,并且我还需要知道发生这种情况的坐标/箱.

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?

推荐答案

使用位置在H中找到nozeros的索引,并使用该索引获取坐标:

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

这篇关于Python中的多维直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆