NumPy: copy() function

copy() function

The copy() function is used to get an array copy of an given object.

Version: 1.15.0


numpy.copy(a, order='K')


Name Description Required /
a Input data. Required
order 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.) optional

Return value:

arr : ndarray
Array interpretation of a.

Example-1:NumPy.copy() function

>>> import numpy as np
>>> a = np.array ( [2, 3, 4])
>>> b = a
>>> c = np.copy(a)
>>> a[0] = 15
>>> b[0] == b[0]
Note that, when we modify a, b changes, but not c:

Example-2:NumPy.copy() function

>>> import numpy as np
>>> a[0] == c[0]

Python - NumPy Code Editor:

Previous: asmatrix()
Next: fromfunction()

Follow us on Facebook and Twitter for latest update.