Array indexing

From: Carl J. Schreck, III <carl_at_nyahnyahspammersnyahnyah>
Date: Wed, 18 Mar 2009 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
Received on Wed Mar 18 2009 - 07:54:35 MDT

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