[Numpy-discussion] linked variables?
Tue Jun 3 18:25:46 CDT 2008
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. On the downside it doesn't work if
you're given a list, but perhaps np.copy() would be better (though it
loses subtype information)? Certainly it's clearer.
More information about the Numpy-discussion