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

Home » Public Forums » archive » Re: Matrix indexing 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
Re: Matrix indexing question [message #38939] Sat, 03 April 2004 02:26 Go to previous message
Chris Lee is currently offline  Chris Lee
Messages: 101
Registered: August 2003
Senior Member
In article <gm1r60p1cdu66r7h8b1bornsh99m1aa05d@4ax.com>, "Matt Feinstein"
<nospam@here.com> wrote:


> If I set
>
> x = [[1,2,3,4,5,6],[7,8,9,10,11,12]]
> then (case A)
> print, x[[3,4],[1,0]]
> gives
> 10 5
> which is slick, and is the kind of indexing I want. However, if (Case B)
> I set
> y = [[3,4],[1,0]]
> then
> print, x[y]
> gives
>
> 4 5
> 2 1
> which, I guess, is also slick-- but is not what I want. Is there any way
> to set a variable 'y' that will give me the kind of indexing in Case A?
> And, yes, I know that I can set
> y = [9, 4]
> and get the 'right' answer. Is this the only way? Matt Feinstein
> --
> There is no virtue in believing something that can be proved to be true.

Hi Matt,

I have two answers, neither is particularly clean.

;1
print, x[y[*,0], y[*,1]]
10 5

;2 , the generic,Index the elements yourself, method.

x=[[1,2,3,4,5,6],[7,8,9,10,11]]
y=[[3,4],[1,0]]
;;;;;
dx=size(x, /dimensions)
dy=size(y,/dimensions)

q=replicate(1,n_elements(dx))
for i=1, n_elements(dx)-1 do for j=0, i-1 do q[i]=q[i]*dx[j]
;;q holds the number of elements per dimension.

indices=y#q ; 2 dimensions in y only

print, x[indices]
10 5

Also, some bounds checking might be needed.

Chris.
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Tabulated output
Next Topic: IDL crashes/hangs while reading images

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

Current Time: Sat Oct 11 13:54:41 PDT 2025

Total time taken to generate the page: 0.55993 seconds