flopscope.

flopscope.numpy.copy

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

Return an array copy of the given object.

Adapted from NumPy docs np.copy

Areacore
Typefree
NumPy Refnp.copy
Cost
0
Flopscope Context

Return array copy.

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

Returns

arr:ndarray

Array interpretation of a.

See also

Notes

This is equivalent to:

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

The 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 flopscope.numpy as fnp

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

>>> x = flops.array([1, 2, 3])
>>> y = x
>>> z = flops.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, flops.copy clears previously set WRITEABLE=False flag.

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