{"id":136383,"date":"2024-09-23T14:27:31","date_gmt":"2024-09-23T08:57:31","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?page_id=136383"},"modified":"2024-09-23T14:27:32","modified_gmt":"2024-09-23T08:57:32","slug":"structured-arrays-in-numpy","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/","title":{"rendered":"Structured Arrays in NumPy"},"content":{"rendered":"\n<p>Structured arrays in NumPy allow you to represent complex data structures with heterogeneous fields, each having a specific data type. This provides a powerful and flexible way to store and manipulate structured data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Creating Structured Arrays<\/strong><\/h3>\n\n\n\n<p>To create a structured array, you need to define a <strong>dtype<\/strong> that specifies the names and data types of each field.<\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\n\ndtype = np.dtype(&#91;('name', np.str_, 20), ('age', np.int32), ('salary', np.float64)])\n\ndata = np.array(&#91;('Alice', 30, 100000), ('Bob', 25, 80000)], dtype=dtype)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Accessing Fields<\/strong><\/h3>\n\n\n\n<p>You can access individual fields of a structured array using field names:<\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>names = data&#91;'name']\nages = data&#91;'age']\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Structured Array Operations<\/strong><\/h3>\n\n\n\n<p>Many NumPy operations can be applied to structured arrays, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Indexing and slicing:<\/strong> Accessing specific elements or subsets of the array.<\/li>\n\n\n\n<li><strong>Arithmetic operations:<\/strong> Performing element-wise arithmetic on fields of compatible data types.<\/li>\n\n\n\n<li><strong>Aggregation functions:<\/strong> Calculating statistics like sum, mean, and standard deviation.<\/li>\n\n\n\n<li><strong>Sorting:<\/strong> Sorting the array based on the values of a specific field.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Advanced Features<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nested Structures:<\/strong> Creating structured arrays within other structured arrays.<\/li>\n\n\n\n<li><strong>Record Arrays:<\/strong> A simplified way to create structured arrays with field names as attributes.<\/li>\n\n\n\n<li><strong>Field Access Using Integers:<\/strong> Accessing fields using integer indices.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example: Employee Database<\/strong><\/h3>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dtype = np.dtype(&#91;('employee_id', np.int32), ('name', np.str_, 30), ('department', np.str_, 20), ('salary', np.float64)])\n\nemployees = np.array(&#91;\n    (1, 'Alice', 'Sales', 50000),\n    (2, 'Bob', 'Marketing', 60000),\n    (3, 'Charlie', 'Engineering', 70000)\n], dtype=dtype)\n\n# Access specific fields\nemployee_ids = employees&#91;'employee_id']\nnames = employees&#91;'name']\n\n# Sort by salary\nsorted_employees = np.sort(employees, order='salary')\n<\/code><\/pre>\n\n\n\n<p>Structured arrays provide a versatile and efficient way to represent and manipulate complex data in NumPy. They are particularly useful for working with tabular data, databases, and scientific datasets.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Structured arrays in NumPy allow you to represent complex data structures with heterogeneous fields, each having a specific data type. This provides a powerful and flexible way to store and manipulate structured data. Creating Structured Arrays To create a structured array, you need to define a dtype that specifies the names and data types of&#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-136383","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>Structured Arrays in NumPy - Tutorial<\/title>\n<meta name=\"description\" content=\"Explore structured arrays in NumPy, which enable the storage of complex data types, providing a flexible way to manage heterogeneous data.\" \/>\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\/structured-arrays-in-numpy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Structured Arrays in NumPy - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Explore structured arrays in NumPy, which enable the storage of complex data types, providing a flexible way to manage heterogeneous data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/\" \/>\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:57:32+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/\",\"name\":\"Structured Arrays in NumPy - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2024-09-23T08:57:31+00:00\",\"dateModified\":\"2024-09-23T08:57:32+00:00\",\"description\":\"Explore structured arrays in NumPy, which enable the storage of complex data types, providing a flexible way to manage heterogeneous data.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Structured Arrays in NumPy\"}]},{\"@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":"Structured Arrays in NumPy - Tutorial","description":"Explore structured arrays in NumPy, which enable the storage of complex data types, providing a flexible way to manage heterogeneous data.","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\/structured-arrays-in-numpy\/","og_locale":"en_US","og_type":"article","og_title":"Structured Arrays in NumPy - Tutorial","og_description":"Explore structured arrays in NumPy, which enable the storage of complex data types, providing a flexible way to manage heterogeneous data.","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-09-23T08:57:32+00:00","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/","name":"Structured Arrays in NumPy - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2024-09-23T08:57:31+00:00","dateModified":"2024-09-23T08:57:32+00:00","description":"Explore structured arrays in NumPy, which enable the storage of complex data types, providing a flexible way to manage heterogeneous data.","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/structured-arrays-in-numpy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Structured Arrays in NumPy"}]},{"@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\/136383","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=136383"}],"version-history":[{"count":2,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136383\/revisions"}],"predecessor-version":[{"id":136413,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136383\/revisions\/136413"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=136383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=136383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=136383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}