[Tutor] When is = a copy and when is it an alias

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Jan 27 15:07:46 CET 2014


On 27/01/2014 09:53, spir wrote:
> On 01/27/2014 07:16 AM, Denis Heidtmann wrote:
>> Running python 2.7 in linux
>>
>> Below are two extremes.  Can I get some guidance on this?
>>
>> Thanks,
>> -Denis H
>>
>>>>> a=zeros((2,3),dtype=int)
>>>>> b=a
>>>>> a[:,0]=[1,2]
>>>>> a
>> array([[1, 0, 0],
>>         [2, 0, 0]])
>>>>> b
>> array([[1, 0, 0],
>>         [2, 0, 0]])
>>>>> a=2
>>>>> a
>> 2
>>>>> b
>> array([[1, 0, 0],
>>         [2, 0, 0]])
>
> Note: your example is strongly obscured by using weird and rare features
> that don't bring any helpful point to the actual problematic concepts
> you apparently want to deal with.
>

Nothing weird and rare about it, just something from the numpy maths 
library and not pure Python.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list