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

Example: numpy.copyto() Method with Example

Python NumPy Programs »



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.