comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Adding x,y events to a 2d array (quickly)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Adding x,y events to a 2d array (quickly) [message #86432 is a reply to message #86430] Thu, 07 November 2013 12:16 Go to previous messageGo to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Thursday, November 7, 2013 1:27:00 PM UTC-6, Dick Jackson wrote:

> I seem to recall someone explaining this behaviour before, and thanks to
>
> Russell, I realize one good way of getting *part* of what you (reasonably!) want
>
> to do. If all of your 'e' values were equal, then you can find how many counts
>
> of each (x,y) pair exist by using Hist_ND:
>
> (http://tir.astro.utoledo.edu/idl/hist_nd.pro)
>
> IDL> Print, Hist_ND(Transpose([[1,1,2],[1,1,2]]), 1, Min=0)
>
> But, in general, to add a varying set of 'e' values to those (x,y) locations...
>
> I have to think a bit...
>

I've got you covered....

Oliver, reverse indices are your friend here, as Russell alluded to. Get the two-dimensional histogram, slightly modified from Dick's version:

h = HIST_ND( [ TRANSPOSE(x), TRANSPOSE(y) ], 1, MIN=0, REVERSE_INDICES=ri )

Since you said you have large arrays, I transpose each individually, and then concatenate.

Now, go through the reverse indices:

totalE = FLTARR(SIZE(h, /DIM))
FOR i=0, N_ELEMENTS(h)-1 do if h[i] GT 0 THEN totalE[i]= TOTAL( e[ri[ri[i]:ri[i+1]-1]])

print, totalE
0.00000 0.00000 0.00000
0.00000 20.0000 0.00000
0.00000 0.00000 10.0000

This is the basic idea. It can be sped up by only looping over the elements of h with non-zero counts (as opposed to "skipping" them as I did here).

Here's some highly recommended reading on histograms: http://www.idlcoyote.com/tips/histogram_tutorial.html
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Non-blocking socket
Next Topic: strange !P.multi[0] behavior??

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 21:07:27 PDT 2025

Total time taken to generate the page: 1.19901 seconds