NumPy

Previous topic

numpy.ascontiguousarray

Next topic

numpy.frombuffer

numpy.copy

numpy.copy(a, order='K', subok=False)[source]

Return an array copy of the given object.

Parameters
aarray_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.)

subokbool, 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).

New in version 1.19.0.

Returns
arrndarray

Array interpretation of a.

See also

ndarray.copy

Preferred method for creating an array copy

Notes

This is equivalent to:

>>> np.array(a, copy=True)  

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