[SciPy-User] problems with numpy array assignment
Gabriele Brambilla
gb.gabrielebrambilla at gmail.com
Tue Mar 4 15:13:05 EST 2014
But the changes I make on PAS=MYMAP[:, hhh. :] will be applied to
G=MYMAP[:, :, :]?
Gabriele
2014-03-04 15:07 GMT-05:00 Gabriele Brambilla <
gb.gabrielebrambilla at gmail.com>:
> thanks.
>
> Gabriele
>
>
> 2014-03-04 15:04 GMT-05:00 Eric Hermes <ehermes at chem.wisc.edu>:
>
> On 3/4/2014 2:00 PM, Gabriele Brambilla wrote:
>>
>> Hi,
>>
>> Something strange happens in my code: I have added the lines after #...
>>
>> MYMAP is a 3d numpy array
>> PAS = MYMAP[:, hhh, :]
>>
>> #multiplying per energy bin width
>> PAS1 = PAS
>> for l in nIph:
>> PAS1[l,:] = PAS1[l,:]*zz
>>
>>
>> But this affect the result I get when I elaborate the data from:
>>
>> EXCT = MYMAP[:, hhh, :]
>>
>> is python continuing to modify the original matrix??
>>
>> Thanks
>>
>> Gabriele
>>
>>
>> _______________________________________________
>> SciPy-User mailing listSciPy-User at scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
>>
>> Gabriele,
>>
>> Numpy arrays are passed as references, so in your code when you modify
>> PAS1 (which inherits the reference to MYMAP from PAS), the changes
>> propogates upwards into MYMAP. If you want to avoid this, you can
>> explicitly create a copy of the array, either by doing:
>>
>> PAS = MYMAP[:,hhh,:].copy()
>>
>> or:
>>
>> PAS1 = PAS.copy()
>>
>> Eric
>>
>> --
>> Eric Hermes
>> J.R. Schmidt Group
>> Chemistry Department
>> University of Wisconsin - Madison
>>
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140304/68e38576/attachment.html>
More information about the SciPy-User
mailing list