NumPy Copy Vs View | LearnHindiTuts

NumPy copy vs view

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 है।

NumPy difference between view() and copy()

copy() method का use करके copy किये गए data में अगर कोई changes होता है , तो original data पर कोई effect नहीं पड़ता है। means वो copied data original data से independent होता है।

NumPy copy() Example

Copy Fullscreen Close Fullscreen Run #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)
Output
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 नहीं हुए हैं।

NumPy view() Example

जबकि view() method का use करके copy किये गए data में अगर कोई changes होता है , तो same changes original में भी होते हैं । या पूरी तरह से original data पर ही dependent होता है।See Example :

Copy Fullscreen Close Fullscreen Run 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))
Output
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 हुए हैं।

Từ khóa » Np.copy Vs =