Elegant copy-by-value

Chad Netzer cnetzer at mail.arc.nasa.gov
Mon Jan 13 23:00:47 CET 2003

On Saturday 11 January 2003 19:51, Carl Banks wrote:
> For example, lists (and Numeric
> arrays) can do this:
>     a = b[:]

Just to be pedantic, Numeric arrays (ie, from the Numeric module) do 
NOT copy when you slice them.  They return views into the slice.  This 
break from Python semantics was done early on as a performance 
enhancement, and can cause no end of confusion (unfortunately).

You copy Numeric arrays with the .copy() method.  I think the 
'numarray' people (who are building a replacement for Numeric) have 
gone back and forth over whether to keep the 
slices-are-views-not-copies feature, and have decided (for 
compatibility w/ Numeric) to keep it as is.

But regardless, since it may matter, Numeric slices do not produce 
copies, but views (or aliases).

Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
cnetzer at mail.arc.nasa.gov

More information about the Python-list mailing list