{"id":136403,"date":"2024-09-23T14:15:18","date_gmt":"2024-09-23T08:45:18","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?page_id=136403"},"modified":"2024-09-23T14:15:19","modified_gmt":"2024-09-23T08:45:19","slug":"views-and-copies","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/","title":{"rendered":"Views and Copies"},"content":{"rendered":"\n<p>Understanding the difference between views and copies is crucial when working with NumPy arrays. Views are references to the same underlying data, while copies create a new array with independent data. This distinction affects how changes made to one array impact the other.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Views<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Shared Data:<\/strong> A view is a reference to the same underlying data as the original array. Any changes made to the view will also be reflected in the original array.<\/li>\n\n\n\n<li><strong>Slicing:<\/strong> Slicing operations typically create views, not copies.<\/li>\n\n\n\n<li><strong>Memory Efficiency:<\/strong> Views are more memory-efficient than copies because they don&#8217;t duplicate the data.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Copies<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Independent Data:<\/strong> A copy creates a new array with its own copy of the data. Changes made to one array will not affect the other.<\/li>\n\n\n\n<li><strong><code>copy()<\/code> Method:<\/strong> The <code class=\"\">copy()<\/code> method explicitly creates a copy of an array.<\/li>\n\n\n\n<li><strong>Deep Copy:<\/strong> A deep copy creates a new array with all its elements copied, including nested arrays and objects.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\n\narr = np.array(&#91;1, 2, 3])\n\n# Create a view\nview = arr&#91;1:3]\n\n# Create a copy\ncopy = arr.copy()\n\n# Modify the view\nview&#91;0] = 10\n\n# Print the original array, view, and copy\nprint(arr)  # Output: &#91;1 10 3]\nprint(view)  # Output: &#91;10 3]\nprint(copy)  # Output: &#91;1 2 3]\n<\/code><\/pre>\n\n\n\n<p>In this example, modifying the view <code class=\"\">view<\/code> also changes the original array <code class=\"\">arr<\/code> because they share the same underlying data. However, modifying the copy <code class=\"\">copy<\/code> does not affect the original array or the view.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>When to Use Views and Copies<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Performance:<\/strong> Use views when you need to work with a subset of an array without copying the entire data.<\/li>\n\n\n\n<li><strong>Memory:<\/strong> If memory is a concern, use views to avoid unnecessary data duplication.<\/li>\n\n\n\n<li><strong>Independence:<\/strong> Use copies when you need to modify an array without affecting the original or other views.<\/li>\n<\/ul>\n\n\n\n<p>By understanding the distinction between views and copies, you can effectively manipulate NumPy arrays while optimizing memory usage and avoiding unintended side effects.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding the difference between views and copies is crucial when working with NumPy arrays. Views are references to the same underlying data, while copies create a new array with independent data. This distinction affects how changes made to one array impact the other. Views Copies Example Python In this example, modifying the view view also&#8230;<\/p>\n","protected":false},"author":16,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-136403","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Views and Copies - Tutorial<\/title>\n<meta name=\"description\" content=\"Understand the concepts of views and copies in NumPy, essential for memory management and data manipulation without unnecessary duplication.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Views and Copies - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Understand the concepts of views and copies in NumPy, essential for memory management and data manipulation without unnecessary duplication.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-23T08:45:19+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/\",\"name\":\"Views and Copies - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2024-09-23T08:45:18+00:00\",\"dateModified\":\"2024-09-23T08:45:19+00:00\",\"description\":\"Understand the concepts of views and copies in NumPy, essential for memory management and data manipulation without unnecessary duplication.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Views and Copies\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Views and Copies - Tutorial","description":"Understand the concepts of views and copies in NumPy, essential for memory management and data manipulation without unnecessary duplication.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/","og_locale":"en_US","og_type":"article","og_title":"Views and Copies - Tutorial","og_description":"Understand the concepts of views and copies in NumPy, essential for memory management and data manipulation without unnecessary duplication.","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-09-23T08:45:19+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/","name":"Views and Copies - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2024-09-23T08:45:18+00:00","dateModified":"2024-09-23T08:45:19+00:00","description":"Understand the concepts of views and copies in NumPy, essential for memory management and data manipulation without unnecessary duplication.","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/views-and-copies\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Views and Copies"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=136403"}],"version-history":[{"count":1,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136403\/revisions"}],"predecessor-version":[{"id":136406,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136403\/revisions\/136406"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=136403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=136403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=136403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}