comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Undocumented array indexing feature?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Undocumented array indexing feature? [message #14086] Mon, 25 January 1999 00:00
wbiagiot is currently offline  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 #14090 is a reply to message #14086] Mon, 25 January 1999 00:00 Go to previous message
Alex Schuster is currently offline  Alex Schuster
Messages: 124
Registered: February 1997
Senior Member
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
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
Re: Undocumented array indexing feature? [message #14091 is a reply to message #14086] Mon, 25 January 1999 00:00 Go to previous message
Mark Buckley is currently offline  Mark Buckley
Messages: 7
Registered: December 1998
Junior Member
J.D. Smith wrote in message <36A8B556.DE735D13@astrosun.tn.cornell.edu>...
> It doesn't work for everything though... as evidenced by:
>
> z=5+6*(y=8)


Even better, I just realised that you can do:

y = 5 + y * ((y=8))

and get y to end up equal to 69!

Bah! Who needs temporary()!!

Mark.


Mark Buckley
Rutherford-Appleton Laboratory
Chilton
Didcot
OXON
UK
Re: Undocumented array indexing feature? [message #14092 is a reply to message #14086] Mon, 25 January 1999 00:00 Go to previous message
wrb1000 is currently offline  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 #14093 is a reply to message #14086] Mon, 25 January 1999 00:00 Go to previous message
Mark Buckley is currently offline  Mark Buckley
Messages: 7
Registered: December 1998
Junior Member
J.D. Smith wrote in message <36A8B556.DE735D13@astrosun.tn.cornell.edu>...
>
> It doesn't work for everything though... as evidenced by:
>
> z=5+6*(y=8)


No, but:

z = 5+6*((y=8))

does!

cheers,

Mark.

Mark Buckley
Rutherford-Appleton Laboratory
Chilton
Didcot
OXON
UK.
Re: Undocumented array indexing feature? [message #14104 is a reply to message #14086] Fri, 22 January 1999 00:00 Go to previous message
Robert S. Hill is currently offline  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 Go to previous message
J.D. Smith is currently offline  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 Go to previous message
Liam Gumley is currently offline  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 Go to previous message
wbiagiot is currently offline  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 Go to previous message
Craig Markwardt is currently offline  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
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: how do i read compressed tiff files?
Next Topic: Re: Processing Audio

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:33:15 PDT 2025

Total time taken to generate the page: 0.00496 seconds