numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
copy(a, order='K', subok=False)

Notes

This is equivalent to:

>>> np.array(a, copy=True)  #doctest: +SKIP

Parameters

a : array_like

Input data.

order : {'C', 'F', 'A', 'K'}, optional

Controls the memory layout of the copy. 'C' means C-order, 'F' means F-order, 'A' means 'F' if a is Fortran contiguous, 'C' otherwise. 'K' means match the layout of a as closely as possible. (Note that this function and ndarray.copy are very similar, but have different default values for their order= arguments.)

subok : bool, optional

If True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (defaults to False).

versionadded

Returns

arr : ndarray

Array interpretation of a.

Return an array copy of the given object.

See Also

ndarray.copy

Preferred method for creating an array copy

Examples

Create an array x, with a reference y and a copy z:

>>> x = np.array([1, 2, 3])
... y = x
... z = np.copy(x)

Note that, when we modify x, y changes, but not z:

>>> x[0] = 10
... x[0] == y[0] True
>>> x[0] == z[0]
False

Note that, np.copy clears previously set WRITEABLE=False flag.

>>> a = np.array([1, 2, 3])
... a.flags["WRITEABLE"] = False
... b = np.copy(a)
... b.flags["WRITEABLE"] True
>>> b[0] = 3
... b array([3, 2, 3])

Note that np.copy is a shallow copy and will not copy object elements within arrays. This is mainly important for arrays containing Python objects. The new array will contain the same object which may lead to surprises if that object can be modified (is mutable):

>>> a = np.array([1, 'm', [2, 3, 4]], dtype=object)
... b = np.copy(a)
... b[2][0] = 10
... a array([1, 'm', list([10, 3, 4])], dtype=object)

To ensure all elements within an object array are copied, use copy.deepcopy :

>>> import copy
... a = np.array([1, 'm', [2, 3, 4]], dtype=object)
... c = copy.deepcopy(a)
... c[2][0] = 10
... c array([1, 'm', list([10, 3, 4])], dtype=object)
>>> a
array([1, 'm', list([2, 3, 4])], dtype=object)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.nan_to_num astropy.io.fits.fitsrec.FITS_rec.copy numpy.ma.core.copy scipy.signal._signaltools.correlate2d numpy.ma.core.masked_where

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/function_base.py#846
type: <class 'function'>
Commit: