Re: Array indexing

From: Saji N. Hameed <saji_at_nyahnyahspammersnyahnyah>
Date: Wed, 18 Mar 2009 23:37:00 +0900

Hopefully my code is correct.

dims=dimsizes(data)
nx=dims(1)
ny=dims(0)
xy=y+x*ny
d1d=ndtooned(data)
result=d1d(xy)
print(result)

saji

---
* Carl J. Schreck, III <carl_at_atmos.albany.edu> [2009-03-18 09:54:35 -0400]:
> I have a 2-d array and a series of ordered pairs that reference points
> within that array.  I would like to make a list of the data referenced
> by those points.  It seems like there should be a way to do it without
> a do loop, but I can't figure one out.
> 
> Here is a simple example of how it works with the loop:
> 
>   data = (/ (/ 1, 2, 3 /) , \\
>             (/ 4, 5, 6 /) , \\
>             (/ 7, 8, 9 /) /)
> 
>   x = (/ 0, 0, 1, 2 /)
>   y = (/ 0, 1, 2, 1 /)
> 
>   output = new( 4, integer )
> 
>   do i = 0, 3
>     output(i) = data(x(i),y(i))
>   end do
> 
> So output ends up the way I want it: (/ 1, 2, 6, 8 /)
> 
> If I instead try output = data(x,y), it gives me a 4x4 array, the
> diagonal of which is what I want.  It's a pretty minor inconvenience
> to put the loop there, but I just wanted to make sure I wasn't missing
> a "cleaner" way to do it.
> 
>         Thanks!
>         Carl
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> 
-- 
Saji N. Hameed
APEC Climate Center          				+82 51 668 7470
National Pension Corporation Busan Building 12F         
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705			saji_at_apcc21.net
KOREA
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 18 2009 - 08:37:00 MDT

This archive was generated by hypermail 2.2.0 : Wed Mar 18 2009 - 14:50:21 MDT