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

Home » Public Forums » archive » Tricky data-summing question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Tricky data-summing question [message #43934] Tue, 03 May 2005 13:27
M. Katz is currently offline  M. Katz
Messages: 69
Registered: May 2005
Member
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
[Message index]
 
Read Message
Previous Topic: Re: wrong results...
Next Topic: Program architecture question

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

Current Time: Fri Oct 10 06:19:21 PDT 2025

Total time taken to generate the page: 0.39935 seconds