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

Home » Public Forums » archive » Re: Pasting subarray into array with compound assignment
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: Pasting subarray into array with compound assignment [message #53596] Sat, 21 April 2007 06:21 Go to next message
m.avdeev@gmail.com is currently offline  m.avdeev@gmail.com
Messages: 2
Registered: April 2007
Junior Member
Thanks a lot, Vince!
It works indeed, although i still don't understand why my code didn't.
According to the manual, only a starting point is needed for pasting
an array into another one...
Re: Pasting subarray into array with compound assignment [message #53601 is a reply to message #53596] Fri, 20 April 2007 14:34 Go to previous messageGo to next message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Apr 20, 12:29 pm, hradilv <hrad...@yahoo.com> wrote:
> On Apr 19, 7:37 pm, "m.avd...@gmail.com" <m.avd...@gmail.com> wrote:
>
>> i'm trying to use the advantage of "+=" when reshaping 2d array to 1d
>
>> Can anyone tell me why the following produce different values?
>> (difference in shape and type of the results is not a problem)
>
>> a1=indgen(3,7) & for i=0,2 do a2[0,i*2]+=a1[i,*] & print,a2
>
>> a1=indgen(3,7) & a2=intarr(3,11) & for i=0,2 do a2[i,i*2]=a1[i,*] &
>> a2=total(a2,1) & print,a2
>
>> thanks,
>> max
>
> Decompose the += into a2[0,2] = a2[0,2] + a1[1,*] (for i=1, for
> instance).
>
> The RHS is 6 + a1[1,*] which is transpose(7,10,13,16,19,22,25). This
> then gets placed into the a2 array at position [0,2]
>
> Same for i=2...

This will work:
a1=indgen(3,7) & a2=intarr(3,11) & for i=0,2 do
a2[0,i*2:i*2+7-1]+=a1[i,*] & print,a2
Re: Pasting subarray into array with compound assignment [message #53609 is a reply to message #53601] Fri, 20 April 2007 10:29 Go to previous messageGo to next message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Apr 19, 7:37 pm, "m.avd...@gmail.com" <m.avd...@gmail.com> wrote:
> i'm trying to use the advantage of "+=" when reshaping 2d array to 1d
>
> Can anyone tell me why the following produce different values?
> (difference in shape and type of the results is not a problem)
>
> a1=indgen(3,7) & for i=0,2 do a2[0,i*2]+=a1[i,*] & print,a2
>
> a1=indgen(3,7) & a2=intarr(3,11) & for i=0,2 do a2[i,i*2]=a1[i,*] &
> a2=total(a2,1) & print,a2
>
> thanks,
> max

Decompose the += into a2[0,2] = a2[0,2] + a1[1,*] (for i=1, for
instance).

The RHS is 6 + a1[1,*] which is transpose(7,10,13,16,19,22,25). This
then gets placed into the a2 array at position [0,2]

Same for i=2...
Re: Pasting subarray into array with compound assignment [message #53729 is a reply to message #53596] Mon, 23 April 2007 09:25 Go to previous message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Apr 21, 8:21 am, "m.avd...@gmail.com" <m.avd...@gmail.com> wrote:
> Thanks a lot, Vince!
> It works indeed, although i still don't understand why my code didn't.
> According to the manual, only a starting point is needed for pasting
> an array into another one...

That's true - only a "starting point" is needed when pasting. The
problem is that when you use the += assigment, the starting point is
"translated" to a scalar, i.e. the value at that starting point. The
sum of the scalar with the vector is then pasted at the starting point.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Xinteranimate and plots
Next Topic: Re: 3D congrid without interpolation

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

Current Time: Wed Oct 08 15:50:29 PDT 2025

Total time taken to generate the page: 0.00497 seconds