Re: Undocumented array indexing feature? [message #14086] |
Mon, 25 January 1999 00:00 |
wbiagiot
Messages: 59 Registered: January 1999
|
Member |
|
|
In article <36AC8341.EC8@rosa.mpin-koeln.mpg.de>,
Alex Schuster <alex@rosa.mpin-koeln.mpg.de> wrote:
> wrb1000@my-dejanews.com wrote:
>
>> This is veering offtopic, but I'd just like to add my two cents.
>> IDL, like C, has many constructs that may add placed on a line to
>> condense the actual length of the program. However, just like C, the
>> readablity and understanding factors tend to drop. I intend to use the
>> a=(b=(c=1)) example. I always wondered how to initialize multiple variables
>> on the same IDL line.
>
> Now that's an easy one:
>
> IDL> a=1 & b=2 & c=3 & d=4 &
>
> Voila, one line :-)
>
> Alex
Oh, I knew that one, Alex. Anyone know which method offers faster execution -
a = 0 & b = 0 * OR * a = (b = 0)
this is important when applying the same principle to large arrays. At least
to those of us with slower PCs :(
Thanks,
Bill B.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
|
|
|
|
|
Re: Undocumented array indexing feature? [message #14092 is a reply to message #14086] |
Mon, 25 January 1999 00:00  |
wrb1000
Messages: 9 Registered: January 1999
|
Junior Member |
|
|
In article <Pine.SO4.4.03.9901221328390.15597-100000@virgil.gsfc.nasa.gov>,
"Robert S. Hill" <bhill@virgil.gsfc.nasa.gov> wrote:
> On Fri, 22 Jan 1999, J.D. Smith wrote:
>>> Liam Gumley wrote:
>>>> Here's a way to index an array I hadn't seen before:
>>>>
>>>> print, (a[x,*])[*,y]
>> It doesn't work for everything though... as evidenced by:
>> z=5+6*(y=8)
>> JD
>
> Ah, but try
>
> z=5+6*((y=8))
>
Hi guys,
This is veering offtopic, but I'd just like to add my two cents.
IDL, like C, has many constructs that may add placed on a line to
condense the actual length of the program. However, just like C, the
readablity and understanding factors tend to drop. I intend to use the
a=(b=(c=1)) example. I always wondered how to initialize multiple variables
on the same IDL line.
Thanks,
Bill B.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
|
|
|
|
Re: Undocumented array indexing feature? [message #14104 is a reply to message #14086] |
Fri, 22 January 1999 00:00  |
Robert S. Hill
Messages: 11 Registered: January 1998
|
Junior Member |
|
|
On Fri, 22 Jan 1999, J.D. Smith wrote:
>> Liam Gumley wrote:
>>> Here's a way to index an array I hadn't seen before:
>>>
>>> print, (a[x,*])[*,y]
> It doesn't work for everything though... as evidenced by:
> z=5+6*(y=8)
> JD
Ah, but try
z=5+6*((y=8))
I guess it ain't C, is it? Offhand, I can't think of a way to make this
seem like consistent syntax.
Bob Hill
--
Robert.S.Hill.1@gsfc.nasa.gov Phone: 301-286-3624
Raytheon ITSS / Code 681, NASA/GSFC, Greenbelt, MD 20771
|
|
|
Re: Undocumented array indexing feature? [message #14105 is a reply to message #14104] |
Fri, 22 January 1999 00:00  |
J.D. Smith
Messages: 214 Registered: August 1996
|
Senior Member |
|
|
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 |*|
|
|
|
Re: Undocumented array indexing feature? [message #14107 is a reply to message #14104] |
Fri, 22 January 1999 00:00  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
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.
---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
1225 W. Dayton St., Madison WI 53706, USA
Phone (608) 265-5358, Fax (608) 262-5974
http://cimss.ssec.wisc.edu/~gumley
|
|
|
Re: Undocumented array indexing feature? [message #14112 is a reply to message #14104] |
Thu, 21 January 1999 00:00  |
wbiagiot
Messages: 59 Registered: January 1999
|
Member |
|
|
Liam,
Actually, I don't remember seeing this feature documented either, but I use
it quite extensively to access individual indices from procedure/functions that
return an array (such as "WHERE", "SIZE", etc.) Since the data that you've
enclosed in parameters constitutes an array (a subset of your original array
actually), you are further indexing into the new 'subarray'.
An example:
Retrieve the 3rd nonzero element of integer array 'a':
a = [1,0,2,0,3,4,5,6]
result = (WHERE(A))[2] ; array indexing starts from 0
result should equal 3.
If the format of this post is lousy, it is because it is my very
first within the newsgroups. Help this helps.
BTW - message to D. Fanning. Your web site has been a tremendous service
to me and I have learned many concepts from you. Many thanks.
Bill B.
|
|
|
Re: Undocumented array indexing feature? [message #14113 is a reply to message #14112] |
Thu, 21 January 1999 00:00  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
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
------------------------------------------------------------ --------------
|
|
|