Home »
Python »
Python Programs
numpy.copyto() Method with Example
Learn about the numpy.copyto() method in Python, how does it work?
Submitted by Pranit Sharma, on March 04, 2023
Python - numpy.copyto() Method
numpy.cpoyto() method is used to make a copy of all the elements of a numpy array. It copies values from one array to another where broadcasting is necessary.
Syntax
numpy.copyto(dst, src, casting='same_kind', where=True)
Parameter(s)
- dst: array in which values are copied
- src: array from which values are copied
- casting: there are different types of casting commands like 'no', 'equiv', 'safe', 'same_kind', 'unsafe'.
Let us understand with the help of an example,
Python program to demonstrate the example of numpy.copyto() Method
# Import numpy
import numpy as np
# Creating a numpy array
arr = np.array([4, 5, 6])
# Creating another array
arr2 = [1, 2, 3]
# Display original array
print("Original Array:\n",arr,"\n")
# Copying arr1 into arr2
np.copyto(arr,arr2)
# Display result
print("Result:\n",arr)
Output
Python NumPy Programs »