[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Undocumented array indexing feature?



Liam Gumley wrote:
> 
> Liam Gumley wrote:
> > Here's a way to index an array I hadn't seen before:
> >
> > a = indgen(10,10)
> > x = [3,5,8,9]
> > y = [2,7]
> > print, (a[x,*])[*,y]
> >       23      25      28      29
> >       73      75      78      79
> >
> > Does anyone know where this feature (i.e. enclosing an array with
> > parentheses and appending an index) is documented? I couldn't find it in
> > my printed IDL 5.0 documentation.
> 
> To answer my own question, a careful reading of Chapter 5 of 'Building
> IDL Applications' p. 60
> (ftp://ftp.rsinc.com/pub/idl_5.2/info/docs/building.pdf)
> revealed the following:
> 
> "The syntax of a subscript reference is:
> Variable_Name[Subscript_ List]
> or
> (Array_Expression)[Subscript_List]"
> 
> Thanks to Bill and Craig for their replies.
> 

Array indexing isn't the only place parentheses are useful... 

try this sometime:

a=(b=(c=1))

Basically, parentheses just instruct the command parser to iterate as
many times as necessary to remove them all.  Other examples:

print,(x=5)

It doesn't work for everything though... as evidenced by:

z=5+6*(y=8)


JD

-- 
 J.D. Smith                             |*|      WORK: (607) 255-5842    
 Cornell University Dept. of Astronomy  |*|            (607) 255-6263
 304 Space Sciences Bldg.               |*|       FAX: (607) 255-5875 
 Ithaca, NY 14853                       |*|