If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
NumPy module में ndarray Object का copy() और view() दोनों methods का use array data को copy करने के लिए किया जाता है। लेकिन इन दोनों methods में एक major difference है।
copy() method का use करके copy किये गए data में अगर कोई changes होता है , तो original data पर कोई effect नहीं पड़ता है। means वो copied data original data से independent होता है।
#import numpy module.
import numpy as np
org_arr = np.array([10, 20, 30, 40, 50])
#now copy data and made some changes.
copy_arr = org_arr.copy()
copy_arr[0] = 60
print('Original Data : ', org_arr)
print('Copied Data : ', copy_arr)
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py Original Data : [10 20 30 40 50] Copied Data : [60 20 30 40 50]
Example में आप clearly देख सकते हैं , कि copied data में changes करने पर original data में कोई changes नहीं हुए हैं।
जबकि view() method का use करके copy किये गए data में अगर कोई changes होता है , तो same changes original में भी होते हैं । या पूरी तरह से original data पर ही dependent होता है।
See Example :
import numpy as np
org_arr = np.array([10, 20, 30, 40, 50])
#now copy data and made some changes using view() mwthod.
copy_arr = org_arr.view()
copy_arr[0] = 60
print('Original Data : ', org_arr)
print('Copied Data : ', copy_arr))
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py Original Data : [60 20 30 40 50] Copied Data : [60 20 30 40 50]
Now you can see , view() method का use करके copy किये गए data में changes करने पर original data में भी changes हुए हैं।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook