bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / ma / core / copy
function
numpy.ma.core:copy
source: build-install/usr/lib/python3.14/site-packages/numpy/ma/core.py :7063
Summary
Return a copy of the array.
Parameters
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 and numpy.copy are very similar but have different default values for their order= arguments, and this function always passes sub-classes through.)
Notes
This function is the preferred method for creating an array copy. The function numpy.copy is similar, but it defaults to using order 'K', and will not pass sub-classes through by default.
Examples
import numpy as np x = np.array([[1,2,3],[4,5,6]], order='F')
y = x.copy()
x.fill(0)
x
y
y.flags['C_CONTIGUOUS']
For arrays containing Python objects (e.g. dtype=object),
the copy is a shallow one. 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 = a.copy() b[2][0] = 10 aTo 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 a
See also
- numpy.copy
Similar function with different default behavior
- numpy.copyto
Aliases
-
numpy.ma.copy