[Numpy-discussion] linked variables?
Tue Jun 3 19:02:54 CDT 2008
On Tue, Jun 3, 2008 at 6:25 PM, Anne Archibald
> 2008/6/3 Robert Kern <firstname.lastname@example.org>:
>> Python does not copy data when you assign something to a new variable.
>> Python simply points the new name to the same object. If you modify
>> the object using the new name, all of the other names pointing to that
>> object will see the changes. If you want a copy, you will need to
>> explicitly make one. For numpy arrays, the best way to do this is to
>> use array().
>> m_i = array(m_o)
> Is array() really the best way to copy an array? I would have thought
> m_i = m_o.copy() would be better - requiring less of array's clever
> guessing, and preserving subtypes.
The latter is true, but I didn't want to get into subtypes. In this
case, array's clever guessing involves recognizing that it is an
ndarray and doing the right thing. There is no recursive traversal
like with lists of lists.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion