[Numpy-discussion] _clone, copy, view

Todd Miller jmiller at stsci.edu
Thu Jan 15 07:07:06 CST 2004

On Thu, 2004-01-15 at 09:30, Colin J. Williams wrote:
> It would help if someone could describe the intended functional 
> differences between _clone, copy and view in numarray.

a.copy() returns a new array object with a copy of a's data. a's
dictionary attributes are currently aliased, not deep copied.  That may
not be the way it should be.  The copy is assumed to be a C_ARRAY,
meaning it is aligned, not byteswapped, and contiguous.  Thus, copy()
is sometimes used as a cleanup operation.

a.view() returns a shallow copy of a.  Most importantly, the shallow
copy aliases the same data as a.  Views are used to look at the same
data buffer in some new way, perhaps with a different shape, or perhaps
as a subset of the original data.  A view has the same special
properties as the original, e.g. if the original is byteswapped, so is
the view.

a._clone() is an implementation detail of the generic take() method. 
The generic take() method is overridden for numerical arrays,  but
utilized for object arrays.  clone()'s purpose is to return a new array
of the same type as 'a' but with a different shape and total number of
elements.  Thus, clone() is useful for creating result arrays for take
based on the input array being taken from.
> Colin W.

Todd Miller 			
Space Telescope Science Institute
3700 San Martin Drive
Baltimore MD, 21030
(410) 338 - 4576

More information about the Numpy-discussion mailing list