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

Home » Public Forums » archive » Re: Array subscript question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Array subscript question [message #19222 is a reply to message #19199] Thu, 02 March 2000 00:00 Go to previous messageGo to previous message
Steve Hartmann is currently offline  Steve Hartmann
Messages: 21
Registered: March 2000
Junior Member
"Kenneth P. Bowman" wrote:

> Can someone explain this behavior to me? I can't find anything in the
> documentation that states that repeated subscripts are handled
> differently.
>
> IDL> a = FINDGEN(5)
> IDL> i = [1, 2, 3]
> IDL> a[i] = a[i] + 10.0
> IDL> PRINT, a
> 0.00000 11.0000 12.0000 13.0000 4.00000
>
> This is the behavior I expect.
>
> IDL> a = FINDGEN(5)
> IDL> i = [2, 2, 2]
> IDL> a[i] = a[i] + 10.0
> IDL> PRINT, a
> 0.00000 1.00000 12.0000 3.00000 4.00000
>
> Why does it only do the operation *once* when
> IDL> HELP, a[i]
> <Expression> FLOAT = Array[3]
>
> IDL> a = FINDGEN(5)
> IDL> i = [2, 2, 2]
> IDL> a[i] = a[i] + [10.0, 10.0, 10.0]
> IDL> PRINT, a
> 0.00000 1.00000 12.0000 3.00000 4.00000
>
> Even this doesn't help.
>
> Ken
>
>

The expression on the right is evaluated first. So your last example,

a[i] = a[i] + [10.0, 10.0, 10.0]

could be written as,

[ a[2], a[2], a[2] ] = [ a[2], a[2], a[2] ] + [10.0, 10.0, 10.0]

or,

[ a[2], a[2], a[2] ] = [ 12.0, 12.0, 12.0 ]

which is the same as,

a[2] = 12.0
a[2] = 12.0
a[2] = 12.0

So the operation does occur more than once, but it's just the same
operation. If you try a[i] = a[i] + [x, y, z], a[2] will equal 'z', since
that expression was executed last.

I hope this helps,
Steve Hartmann
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Radon Transform
Next Topic: Re: IDL and 3D Image

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

Current Time: Fri Oct 10 14:14:53 PDT 2025

Total time taken to generate the page: 1.40189 seconds