NumPy: copyto() function
numpy.copyto() function
The copyto() function is used to copy values from one array to another, broadcasting as necessary.
Raises a TypeError if the casting rule is violated, and if where is provided, it selects which elements to copy.
New in version 1.7.0.
Version: 1.15.0
Syntax:
numpy.copyto(dst, src, casting=’same_kind’, where=True)
Parameter:
Name | Description | Required / Optional |
---|---|---|
dst | The array into which values are copied. | Required |
src | The array from which values are copied. | Required |
casting | Controls what kind of data
casting may occur when copying.
|
Optional |
where | A boolean array which is broadcasted to match the dimensions of dst, and selects elements to copy from src to dst wherever it contains the value True. | Optional |
Example: numpy.copyto()
def copy_parameters_from(self, params):
"""Copies parameters from another source without reallocation.
Args:
params (Iterable): Iterable of parameter arrays.
"""
for dst, src in zip(self.parameters, params):
if isinstance(dst, numpy.ndarray):
if isinstance(src, numpy.ndarray):
numpy.copyto(dst, src)
else:
dst[:] = src.get()
elif isinstance(src, numpy.ndarray):
dst.set(src)
else:
cuda.copy(src, out=dst)
Python - NumPy Code Editor:
Previous: NumPy Array manipulation Home
Next: Changing array shape reshape()
- 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