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 #19199] Fri, 03 March 2000 00:00 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
"J.D. Smith" wrote:
>
> "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
>
> A fast solution (better than loops in many cases), is listed in the manual using
> the histogram function (everyone's favorite), though it works for integer (long
> or otherwise) types only.

Actually, that's not really true. The sun is out and temporarily incapacitated
by reasoning abilities.

As long as your i vector is >=0 and <n_elements(A), you can do:

a=a+histogram(i,MIN=0,MAX=n_elements(a)-1)*10.

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 |*|
[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: Thu Oct 09 21:03:37 PDT 2025

Total time taken to generate the page: 0.96075 seconds