Dear Matt
what do you think on this solution
a=[3,4]
b=[1,0]
x = [[1,2,3,4,5,6],[7,8,9,10,11,12]]
print,x[[a],[b]]
10 5
My explanation:
The problem here is that there are the same signs used to create an array
and the same signs are used to assign an index array.
May be David has a better idea. I hink what happens is by using an operation
you did by {{{ print, x[[3,4],[1,0]] }}} the outer [] are used to adress
the values because then they are not interpreted to create a new array.
If you do create a temporary array like this example shows. It is not
necessary to create the {{{y}}} variable. You will get the results you see
in your example too.
print, (x)([[3,4],[1,0]])
4 5
2 1
Both could be wanted and both could give terrible results if they are not
clear described or coded.
Thanks for the advice!
Reimar
Matt Feinstein 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.
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|