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

Home » Public Forums » archive » Re: Tricky data-summing question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Tricky data-summing question [message #43929] Tue, 03 May 2005 13:50
Sean Davis is currently offline  Sean Davis
Messages: 19
Registered: August 1999
Junior Member
M. Katz wrote:

> Here's a tricky question I've been wrestling with, in need of
> inspiration.
>
> I've got an array of raw data that I want to downsample into an output
> array, but in a special way. I have an array of index values telling me
> where to put the raw input for summation. It looks like this
>
> in = [0.1,0.2,0.3, 1, 2, 10,20]
> w = [ 0, 0, 0, 1, 2, 3, 3]
> out = fltarr(5)
>
> ; The idea is that, following w, the first three elements of in[] need
> to be summed into out(0). Also, out[3] will contain the sum of 10 and
> 20.
>
> ; This slow code does what we want, but inelegantly.
> for i=0,n_elements(in)-1 do out(w(i)) += in(i)
>
> out = [0.6, 1., 2., 30., 0.] ; this is the right answer
>
> In practice in[] and w[] have thousands of elements. I'm wondering if
> there's a quick, clever trick with histogram or something that would
> make this calculation fly.
>
> Thanks,
> M. Katz
If you use histogram and the REVERSE_IND keyword, you could perform this
operation, and you would only have to sum over each bin in the histogram,
which i presume would be a smaller number than summing over n_elements(in).

-Sean
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Determining install directory
Next Topic: Re: Determining install directory

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

Current Time: Thu Oct 09 21:11:37 PDT 2025

Total time taken to generate the page: 0.66271 seconds