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()
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises