subscripting arrays [message #46258] |
Sun, 13 November 2005 20:47  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
Hi all,
this is probably simple, but I can't figure it out right now:
I want to extract an element from a 2d array, and I have the 2d
subscripts of that element available as a 2-element vector.
IDL> a = dist(300)
IDL> b = [30, 50]
IDL> print, a[b]
30.0000 50.0000
Not what I want. What I want is
IDL> print, a[b[0], b[1]]
58.3095
Is there a more elegant way than splitting b up?
Thanks,
Benjamin
|
|
|
Re: subscripting arrays [message #46417 is a reply to message #46258] |
Tue, 22 November 2005 01:36  |
Chris Lee
Messages: 101 Registered: August 2003
|
Senior Member |
|
|
Benjamin Hornberger wrote:
> Hi all,
>
> this is probably simple, but I can't figure it out right now:
>
> I want to extract an element from a 2d array, and I have the 2d
> subscripts of that element available as a 2-element vector.
>
> IDL> a = dist(300)
> IDL> b = [30, 50]
> IDL> print, a[b]
> 30.0000 50.0000
>
> Not what I want. What I want is
>
> IDL> print, a[b[0], b[1]]
> 58.3095
>
> Is there a more elegant way than splitting b up?
>
> Thanks,
> Benjamin
You can get the correct answer using the one-dimensional index.
a=dist(300)
b=[30,50]
scale=[1,300]
print, a[total(b*scale)]
but it's not very elegant.
Chris.
|
|
|