bundles / numpy 2.4.3 / numpy / copy
_ArrayFunctionDispatcher
numpy:copy
Signature
def copy ( a , order = K , subok = False ) Summary
Return an array copy of the given object.
Parameters
a: array_likeInput data.
order: {'C', 'F', 'A', 'K'}, optionalControls the memory layout of the copy. 'C' means C-order, 'F' means F-order, 'A' means 'F' if
ais Fortran contiguous, 'C' otherwise. 'K' means match the layout ofaas closely as possible. (Note that this function andndarray.copyare very similar, but have different default values for their order= arguments.)subok: bool, optionalIf True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (defaults to False).
Returns
arr: ndarrayArray interpretation of
a.
Notes
This is equivalent to:
>>> np.array(a, copy=True) #doctest: +SKIPThe copy made of the data is shallow, i.e., for arrays with object dtype, the new array will point to the same objects. See Examples from ndarray.copy.
Examples
import numpy as np
✓x = np.array([1, 2, 3]) y = x z = np.copy(x)✓
x[0] = 10
✓x[0] == y[0] x[0] == z[0]✗
a = np.array([1, 2, 3]) a.flags["WRITEABLE"] = False b = np.copy(a) b.flags["WRITEABLE"] b[0] = 3 b✓
See also
- ndarray.copy
Preferred method for creating an array copy
Aliases
-
numpy.copy