

{"id":123262,"date":"2023-11-02T17:43:23","date_gmt":"2023-11-02T12:13:23","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=123262"},"modified":"2024-02-28T11:54:21","modified_gmt":"2024-02-28T06:24:21","slug":"python-program-on-array-attributes","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/","title":{"rendered":"Python Program on Array Attributes"},"content":{"rendered":"<p>In this article, we will explore a Python program that delves into the attributes of arrays using the NumPy library. NumPy is a powerful library for numerical and mathematical operations in Python, and it provides an array object that supports various attributes for efficient array manipulation. The program demonstrates different attributes such as shape, size, data type, and dimensionality, providing insights into the structure and characteristics of arrays in NumPy.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>Basic Python Knowledge (Variables, Data Types, Syntax)<\/li>\n<li>Familiarity with the Basics of the NumPy Library (Role in Numerical Computing, Basic Array Operations)<\/li>\n<\/ul>\n<h3>Topic Explanation<\/h3>\n<p>This program initiates by importing the NumPy library as &#8216;np&#8217; and constructing arrays with diverse shapes and data types. It proceeds to illustrate several essential attributes of NumPy arrays, encompassing &#8216;reshape()&#8217; for modifying array shape, &#8216;dtype&#8217; for specifying data types, &#8216;size&#8217; for element count, &#8216;itemsize&#8217; for byte size per element, &#8216;shape&#8217; for array dimensions, and &#8216;ndim&#8217; for the number of dimensions.<\/p>\n<p>By demonstrating these attributes, the program offers a practical exploration of NumPy&#8217;s versatility and its role in efficient data manipulation. Readers gain insights into key functionalities for working with arrays, enhancing their comprehension of NumPy as a fundamental library for numerical computing and data analysis in Python.<\/p>\n<h4>Code:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Importing the NumPy library with the alias 'np'\r\nimport numpy as np\r\n\r\n# Creating a 2D NumPy array 'myar' with shape (3, 4)\r\nmyar = np.array([[1, 2, 3, 1], [4, 5, 6, 2], [7, 8, 9, 5]])\r\n\r\n# Printing the original array\r\nprint(\"Original Array:\")\r\nprint(myar)\r\n\r\n# Reshaping the array to a 1D array 'myar1' with 12 elements\r\nmyar1 = myar.reshape(12)\r\n\r\n# Printing the reshaped array\r\nprint(\"\\nReshaped Array:\")\r\nprint(myar1)\r\n\r\n# Creating a NumPy array 'myar' with floating-point values\r\nmyar = np.array([1.2, 2.4, 3.5, 4.5, 5.7, 6.8, 7.9, 8.3, 9.6, 10.7])\r\n\r\n# Creating another NumPy array 'myar' with integer values\r\nmyar = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])\r\n\r\n# Printing the array and its data type\r\nprint(\"\\nArray with Integer Values:\")\r\nprint(myar)\r\nprint(\"Data type of array:\", myar.dtype)\r\n\r\n# Creating a NumPy array 'myar' with integer values\r\nmyar = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])\r\n\r\n# Reshaping the array to a 2D array 'myar1' with shape (3, 4)\r\nmyar1 = myar.reshape(3, 4)\r\n\r\n# Printing the reshaped array\r\nprint(\"\\nReshaped 2D Array:\")\r\nprint(myar1)\r\n\r\n# Printing the size, item size, shape, and number of dimensions of the array\r\nprint(\"\\nArray Information:\")\r\nprint(\"Size of array:\", myar.size)\r\nprint(\"Item Size of array:\", myar.itemsize)\r\nprint(\"Shape of array:\", myar.shape)\r\nprint(\"Number of dimensions:\", myar.ndim)<\/pre>\n<div class=\"df-code-out\">\n<p><strong>Output:<\/strong><\/p>\n<p>Original Array:<br \/>\n[[1 2 3 1]<br \/>\n[4 5 6 2]<br \/>\n[7 8 9 5]]<\/p>\n<p>Reshaped Array:<br \/>\n[1 2 3 1 4 5 6 2 7 8 9 5]<\/p>\n<p>Array with Integer Values:<br \/>\n[1 2 3 4 5 6 7 8 9]<br \/>\nData type of array: int64<\/p>\n<p>Reshaped 2D Array:<br \/>\n[[ 1 2 3 4]<br \/>\n[ 5 6 7 8]<br \/>\n[ 9 10 11 12]]<\/p>\n<p>Array Information:<br \/>\nSize of array: 12<br \/>\nItem Size of array: 8<br \/>\nShape of array: (12,)<br \/>\nNumber of dimensions: 1<\/p>\n<\/div>\n<h4>Code Explanantion:<\/h4>\n<ul>\n<li>Imports the NumPy library with the alias &#8216;np&#8217; for easier usage<\/li>\n<li>Creates a 2D NumPy array &#8216;myar&#8217; with shape (3, 4) and integer values<\/li>\n<li>Prints the original 2D array<\/li>\n<li>Reshapes the 2D array into a 1D array &#8216;myar1&#8217; with 12 elements<\/li>\n<li>Prints the reshaped 1D array<\/li>\n<li>Creates a new NumPy array &#8216;myar&#8217; with floating-point values<\/li>\n<li>Creates another NumPy array &#8216;myar&#8217; with integer values<\/li>\n<li>Prints the integer array and its data type<\/li>\n<li>Creates an integer NumPy array &#8216;myar&#8217; with 12 elements<\/li>\n<li>Reshapes the 1D array into a 2D array &#8216;myar1&#8217; with shape (3, 4)<\/li>\n<li>Prints the reshaped 2D array<\/li>\n<li>Prints size, item size, shape and number of dimensions of the reshaped array<\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p>In summary, this Python program serves as an invaluable resource for readers seeking to delve into the intricacies of array attributes using the powerful NumPy library. It not only offers practical guidance but also illuminates the significance of understanding array structure and characteristics. These insights form the bedrock for proficient numerical computing, data analysis, and scientific research in Python. As readers grasp the capabilities of NumPy arrays, they gain a robust foundation for tackling complex data-centric challenges across a myriad of domains, from machine learning to scientific simulations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will explore a Python program that delves into the attributes of arrays using the NumPy library. NumPy is a powerful library for numerical and mathematical operations in Python, and it&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[28687,10333,28686,28626,28685],"class_list":["post-123262","post","type-post","status-publish","format-standard","hentry","category-python","tag-attributes-of-array-in-python","tag-python","tag-python-array-attributes","tag-python-practical","tag-python-program-on-array-attributes"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Program on Array Attributes - DataFlair<\/title>\n<meta name=\"description\" content=\"Python program serves as an invaluable resource for readers seeking to delve into the intricacies of array attributes using the powerful NumPy library.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Program on Array Attributes - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python program serves as an invaluable resource for readers seeking to delve into the intricacies of array attributes using the powerful NumPy library.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-02T12:13:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-28T06:24:21+00:00\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Program on Array Attributes - DataFlair","description":"Python program serves as an invaluable resource for readers seeking to delve into the intricacies of array attributes using the powerful NumPy library.","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:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/","og_locale":"en_US","og_type":"article","og_title":"Python Program on Array Attributes - DataFlair","og_description":"Python program serves as an invaluable resource for readers seeking to delve into the intricacies of array attributes using the powerful NumPy library.","og_url":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-11-02T12:13:23+00:00","article_modified_time":"2024-02-28T06:24:21+00:00","author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Python Program on Array Attributes","datePublished":"2023-11-02T12:13:23+00:00","dateModified":"2024-02-28T06:24:21+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/"},"wordCount":438,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["attributes of array in python","Python","python array attributes","python practical","python program on array attributes"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/","url":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/","name":"Python Program on Array Attributes - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2023-11-02T12:13:23+00:00","dateModified":"2024-02-28T06:24:21+00:00","description":"Python program serves as an invaluable resource for readers seeking to delve into the intricacies of array attributes using the powerful NumPy library.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-array-attributes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Program on Array Attributes"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=123262"}],"version-history":[{"count":2,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123262\/revisions"}],"predecessor-version":[{"id":134141,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123262\/revisions\/134141"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=123262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=123262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=123262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}