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

Home » Public Forums » archive » The IDL way, summing variable sized slices of array.
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
The IDL way, summing variable sized slices of array. [message #79758] Wed, 04 April 2012 01:00 Go to next message
d19997919 is currently offline  d19997919
Messages: 4
Registered: April 2012
Junior Member
Hi,

I've recently been learning how to use REBIN/REFORM etc. to do the heavy lifting rather than loops, (saving me at least an order of magnitude in execution time in some of the code I'm working with). I have a situation now where I don't know if it's possible to completely remove loops so I was hoping someone more experienced could illuminate me.

In essence the problem is that I have a 3D array which I want to reduce to a 2D array by summing over elements of the first dimension. This wouldn't be an issue apart from the fact that the range of elements that I wish to sum over varies depending on the value of the second dimension.

In code what I have at the moment looks a bit like:

d=DBLARR(nt,nl,ne) ;Array of data
t=DBLARR(nt) ; Array of "axis" values
b=DBLARR(nl,2) ;Array of summation limits
p=DBLARR(nl,ne) ; Array of answer

;<<BIT OF CODE TO FILL THESE ARRAYS>>

FOR i=0L,nl-1 DO BEGIN
tmp=TOTAL(d[b[i,0]:b[i,1],i,*],1) ;Sum elements
p[i,*]=tmp/TOTAL(t[b[i,0]:b[i,1]]) ;Store sum divided by sum of axis (i.e. get average value over summation range)
ENDFOR
RETURN,p

Any help will be appreciated,

Note whilst nl is not necessarily large in the cases I'll be looking at, i'm still interesting in "the IDL way" for this as part of my learning!

Thanks,
David
Re: The IDL way, summing variable sized slices of array. [message #79850 is a reply to message #79758] Thu, 05 April 2012 01:47 Go to previous message
d19997919 is currently offline  d19997919
Messages: 4
Registered: April 2012
Junior Member
Apologies for double post, can't seem to find an edit button. Just a minor bug in the above code

div=div+(div EQ 0)
drift=TEMPORARY(drift)*(div NE 0)+(div EQ 0)

Should be replaced with

drift=TEMPORARY(drift)*(div NE 0)-(div EQ 0)
div=div+(div EQ 0)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: The IDL way, summing variable sized slices of array.
Next Topic: Matrix algebra and index order, A # B vs A ## B

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

Current Time: Wed Oct 08 15:48:10 PDT 2025

Total time taken to generate the page: 0.00594 seconds