Re: indexing arrays with arrays [message #2431] |
Fri, 01 July 1994 02:09 |
robijn
Messages: 18 Registered: June 1994
|
Junior Member |
|
|
In article <Cs7sCo.EFB@space.physics.uiowa.edu>,
Larry Granroth <ljg@space.physics.uiowa.edu> wrote:
>
> IDL> a = fltarr(3)
> IDL> map = [1, 1, 2]
> IDL> a(map) = a(map) + [1.0, 2.0, 3.0]
> IDL> print, a
> 0.00000 2.00000 3.00000
>
> [...] I had hoped that "1.0" and "2.0" would
> have been summed into a(1) and "3.0" into a(2), resulting in
> a = [0.0, 3.0, 3.0].
>
> Why doesn't this work?
>
In IDL a(map) is just a three-element array, filled with values of a.
To this temporary variable [1.0, 2.0, 3.0] is added. The last step
is performing the assignment - simply copying the elements of the
temporary array into the corresponding elements of a according to the
left hand side expression. By now IDL already has 'forgotten' what's on
the right hand side. It copies the elements one by one, thus overwriting
a(0) with 2.0.
Frank
--
_____ ____
/ / / Frank Robijn Internet: Robijn@Strw.LeidenUniv.NL
/___ /___/ Sterrewacht Leiden Bitnet: Robijn@HLERUL51
/ / \ Phone (31) 71 275841 Local: Robijn@HL628
/ / \ Fax : (31) 71 275819 Snail: P.O.Box 9513, 2300 RA Leiden,
The Netherlands
|
|
|