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

Home » Public Forums » archive » indexing
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
indexing [message #65929] Wed, 01 April 2009 18:12 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
I swear I've seen this come up within the past few months, but I can't
find it, so here goes:

Let's say I have a 3D array - think of it as x,y,z if you want. I have
a list of x,y pairs and I want to perform on operation on a given
range in z (say z1:z2) and each x,y pair. For a simple example, let's
say I just want them all up. So, if the following were my x,y pairs:
3 4
2 1
3 7
and my z range was 1:3 then I want
array[3,4,1]+array[3,4,2]+array[3,4,3]
+array[2,1,1]+array[2,1,2]+array[2,1,3]
+array[3,7,1]+array[3,7,2]+array[3,7,3]

Is there a simple representation for this? My standard solution, if
pair is an npair x 2 array containing the x,y pairs, looks something
like this:
nz=z2-z1+1
zindices=rebin(reform(z1+lindgen(nz),1,nz), npair,nz)
xindices=rebin(pair[*,0],npair,nz)
yindices=rebin(pair[*,1],npair,nz)
answer = total(array[xindices,yindices,zindices])

...but if nz and npair are large, generating all of those 2D index
arrays is really wasteful. The following also works:

answer = total(array[pair[*,0],pair[*,1],z1:z2] * rebin(identity
(npair,npair,nz)))

but again generates 2 intermediate npair x npair x nz arrays that are
wasteful if npair is large.

Any takers?

-Jeremy.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: CATCH error problem
Next Topic: Is there a function to calculate the determinant of a N×N matrix?

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

Current Time: Wed Oct 08 17:34:46 PDT 2025

Total time taken to generate the page: 0.00567 seconds