X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 19 Apr 2007 06:28 PM by  anon
Pasting subarray into array with compound assignment
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
19 Apr 2007 06:28 PM
    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

    Deleted User



    New Member


    Posts:
    New Member


    --
    19 Apr 2007 06:28 PM
    I believe you are wanting to know the difference between this statement: for i=0,2 do a2[0,i*2]+=a1[i,*] and this: for i=0,2 do a2[i,i*2]=a1[i,*] no? The one critical difference (given your particular data sets, is that the first statement uses a static '0' subscript, where the second uses a dynamic 'i'. By the way, if you think you may be sharing code with others, it is good programming practise to avoid using the '&' command concatenator operator. That really makes code hard to read. Regards, James Jones
    You are not authorized to post a reply.