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()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework