Re: Positions in 3-d [message #43820 is a reply to message #43805] |
Fri, 29 April 2005 14:45   |
K. Bowman
Messages: 330 Registered: May 2000
|
Senior Member |
|
|
In article <1114797354.327497.219120@f14g2000cwb.googlegroups.com>,
panblosky@gmail.com wrote:
> Hi, I have the following problem. I have a 3xn array, where n can go
> from 32000 to 16.000.000. This array represents positions in space, or
> just lets say x,y,z. The numbers go from 0 to 1. I have a cube of sides
> 1. I divide that cube into a 3-D grid, where my gridsize can go from 32
> to 512 in every direction (depends on how big I want the grid). So, in
> 1-D, the box is going to be divided in:
>
> lon=findgen(n0)/float(n0-1)*float(boxsize)/boxsize
>
> where n0 is the size of the grid (for example, 128) and boxsize is 1.
> The same thing goes for the other two dimensions.
> Now, I want to find what points (x,y,z) lies in which gridcell
> (between lon[i+1] and lon[i] in every direction).
> If I do it with a for loop (together with a where), it will take for
> ever. I have tried sorting, but I just can't get it right. Does
> somebody knows a fast way?
> Thanks,
>
> Pablo
This sounds like a job for ... HISTOGRAM!
It's a bird, it's a plane, no, it's HISTOGRAM!
Compute the indices of the boxes containing each point. Then use HISTOGRAM on
the indices (with REVERSE_INDICES).
David has JD's HISTOGRAM tutorial at
http://www.dfanning.com/tips/histogram_tutorial.html.
Ken Bowman
|
|
|