histograms in 2 (N?) D

I would like to produce histograms in N dimensions, the minimum being in 2D.
Here is an example of what I wish to do:

I have a set of P particles with x and y positions.
I have a rectangular grid, defined by e.g. a sampling in x and a sampling in y, (e.g. samp_x=arange(-15,31,1) ..), and I wish to know how many particles are in each "pixel".

I can do that in many different ways (using searchsorted from numarray, or abruptly using loops, etc) but I am now looking for a simple (fewer lines) and efficient way (as I am treating large sets of particles) to do this so that I would be able to use a function like:

histogram_2D(x,y, samp_x, samp_y) would return a matrix with the number of particles in each corresponding pixel.

showhistogram_2D(x,y, samp_x, samp_y) would display it
[using e.g. imshow or matshow]

Any hint there (I realize this is more a numarray question but I thought of first asking your community first since someone may have done it already)? And maybe also of how to generalize this in N dimensions? (for 1D matplotlib has the hist function..)



Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem