[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Undocumented array indexing feature?
Liam Gumley <Liam.Gumley@ssec.wisc.edu> writes:
>
> 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.
It's not really an array indexing feature per se. In your example, a
temporary expression is first created from a[x,*], and then *that*
temporary expression is indexed according to [*,y]. Internally, IDL
must do some more copying than straight array indexing, so your
operation is not as efficient. On the other hand it probably does
what you want. I like it!
By the way, indexing of expressions is allow, as long as you throw a
pair of parentheses around it. The following sometimes appears in my
code:
n = (size(x))[0]
The result of size(x) is an array; this statement takes the first
element of that array.
Craig
--
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------