Memory Views क्या हैं
Views दो arrays को same data share करने देते हैं ताकि changes दोनों में दिखें, बिना copying के।
In this page:
Syntax
view = arr[start:stop] # shares memory
copy = arr[start:stop].copy() # independent
Memory Views
Slicing, reshape, और transpose आमतौर पर views return करते हैं जो original के साथ memory share करते हैं। .copy() से बनाई एक copy अपना data owns करती है। .base attribute बताता है कि एक array एक view है या नहीं, और np.shares_memory overlap check करता है।
Note:
Views memory और time बचाते हैं, लेकिन एक के जरिए एक change सब में दिखता है।
उदाहरण: Memory views
import numpy as np
a = np.arange(6)
v = a[1:4]
c = a[1:4].copy()
v[0] = 99
print(a)
print("view shares:", np.shares_memory(a, v))
print("copy shares:", np.shares_memory(a, c))
print(v.base is a)
# Output:
# [ 0 99 2 3 4 5]
# view shares: True
# copy shares: False
# True
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- एक view modify करना और यह भूल जाना कि original बदल जाता है
- यह मान लेना कि fancy indexing एक view return करता है
- destructive edits से पहले copy न करना
चैप्टर सारांश
- Slices और reshapes views हैं
- copy() independent data बनाता है
- base owner reveal करता है
- shares_memory overlap check करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: