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
Re: indexing [message #66106 is a reply to message #65929] Thu, 02 April 2009 12:20 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Apr 2, 12:49 pm, "Dick Jackson" <d...@d-jackson.com> wrote:
> Hi all,
>
> Good one, Chris. How about this for getting the subset:
>
> PRO IndexXYPairsOverZ
>
> a = Transpose(IndGen(10,10,10), [2,1,0]) ; Array where, e.g. a[3,0,4]=304
>
> xy = [[3,4],[2,1],[3,7]]
> z0 = 1
> z1 = 3
>
> dims=Size(a,/Dim)
> a = Reform(a, dims[0]*dims[1], dims[2], /Overwrite) ; Reshape a temporarily
> xyIndices = xy[0,*]+xy[1,*]*dims[0]
> subset = a[xyIndices, z0:z1]
> a = Reform(a, dims, /Overwrite)                     ; Restore a's shape
>
> Help, subset
> Print, subset
>
> END
>
> Printed result:
>
> SUBSET          INT       = Array[3, 3]
>      341     211     371
>      342     212     372
>      343     213     373
> Note that the Reforms will take effectively no time at all, and you only
> make one list of indices.
>
> Hope this helps.
>
> Cheers,
> -Dick
>
> --
> Dick Jackson Software Consulting               http://www.d-jackson.com
> Victoria, BC, Canada             +1-250-220-6117       d...@d-jackson.com
>
> "Jeremy Bailin" <astroco...@gmail.com> wrote in message
>
> news:a50cae0f-63e5-47b7-a44e-b5363114855a@r37g2000yqn.google groups.com...
> On Apr 2, 1:34 am, Chris <beaum...@ifa.hawaii.edu> wrote:
>
>> I would have done something like this, accomplishing the summation in
>> two steps
>
>> x = [3, 2, 3]
>> y = [4, 1, 7]
>> sum = total(array[*,*,1:3], 3) ; summed along z direction
>> answer = total(sum[x,y]) ; summed over x,y pairs
>
>> chris
>
> Yeah, that definitely works nicely for total (I like the fact that it
> doesn't need any internal index vectors, and that the intermediate
> stage is a constant size independent of npair and nz), which is what
> I'm doing today. But it wouldn't work for the more generic case where
> I want to do something else to those values - for example, I've needed
> to do the equivalent with median before, and that won't work as a 2-
> step process.
>
> -Jeremy.

Ah, now this is exactly the sort of thing I was looking for! Excellent
job, Dick! As with any elegant solution, now that I look at it, I'm
kicking myself for not figuring it out earlier... but it's a nice
trick to add to the IDL Way Arsenal. :-)=

-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: Thu Oct 09 20:45:47 PDT 2025

Total time taken to generate the page: 0.00453 seconds