Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy: copy() function

copy() function

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

Version: 1.15.0

Syntax:

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

Parameter:

Name Description Required /
Optional
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]
True
Note that, when we modify a, b changes, but not c:

Example-2:NumPy.copy() function

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

Python - NumPy Code Editor:

Previous: asmatrix()
Next: fromfunction()