

{"id":123545,"date":"2023-11-04T11:53:27","date_gmt":"2023-11-04T06:23:27","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=123545"},"modified":"2024-02-28T12:03:12","modified_gmt":"2024-02-28T06:33:12","slug":"python-program-on-matrix-concepts","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/","title":{"rendered":"Python Program on Matrix Concepts"},"content":{"rendered":"<p>In this article, we will explore a Python program that focuses on matrix operations using the NumPy library. NumPy provides extensive support for matrix-related operations, making it a powerful tool for linear algebra and scientific computing.<\/p>\n<p>The program showcases the creation of a NumPy array, converting it into a matrix, and performing various matrix-related functions such as finding the maximum and minimum values, calculating the sum and product, and sorting elements.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>Fundamental Python Knowledge (Variables, Data Types, Syntax)<\/li>\n<li>Basic Familiarity with the NumPy Library (Numerical Computing, Basic Array Operations<\/li>\n<\/ul>\n<h3>Topic Explanation<\/h3>\n<p>This program kicks off by importing the NumPy library as &#8216;np&#8217; and initializing a NumPy array. Subsequently, it delves into the transformation of the array into a NumPy matrix using the &#8216;np.matrix()&#8217; function.<\/p>\n<p>Within the program, readers will explore a range of matrix-related functions, including those for discovering maximum and minimum values, performing summation and multiplication operations, and facilitating the sorting of elements along rows. This comprehensive exploration equips readers with practical insights into matrix operations, enhancing their proficiency in numerical computing and data manipulation with NumPy in Python.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\r\n\r\n# Create a numpy array\r\nmyar=np.array([[10,3,4],[7,6,9],[12,88,9]])  \r\n\r\n# Convert array to matrix\r\nmt1=np.matrix(myar)\r\n\r\n# Print matrix \r\nprint(mt1)\r\n\r\n# Print maximum value in matrix\r\nprint(mt1.max()) \r\n\r\n# Print minimum value in matrix\r\nprint(mt1.min())\r\n\r\n# Print sum of all values in matrix \r\nprint(mt1.sum())\r\n\r\n# Print product of all values in matrix\r\nprint(mt1.prod())\r\n\r\n# Print matrix with each row sorted\r\nprint(\"Sorted elements of Matrix Row :\")\r\nprint(np.sort(mt1))<\/pre>\n<div class=\"df-code-out\">\n<p><strong>Output:<\/strong><\/p>\n<p>[[10 3 4]<br \/>\n[ 7 6 9]<br \/>\n[12 88 9]]<br \/>\n88<br \/>\n3<br \/>\n148<br \/>\n431101440<br \/>\nSorted elements of Matrix Row :<br \/>\n[[ 3 4 10]<br \/>\n[ 6 7 9]<br \/>\n[ 9 12 88]]<\/p>\n<\/div>\n<h4>Code Explanation:<\/h4>\n<ul>\n<li>Import the numpy package with alias np<\/li>\n<li>Create a 3&#215;3 numpy array called myar with the given values<\/li>\n<li>Convert myar to a matrix called mt1 using np.matrix()<\/li>\n<li>Print out mt1 to see the matrix<\/li>\n<li>Print the maximum value in mt1 using the .max() method<\/li>\n<li>Print the minimum value in mt1 using the .min() method<\/li>\n<li>Print the sum of all values in mt1 using the .sum() method<\/li>\n<li>Print the product of all values in mt1 using the .prod() method<\/li>\n<li>Print a message saying we will print the sorted elements<\/li>\n<li>Use np.sort() to sort each row of mt1 and print the sorted matrix<\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p>In summary, this Python program serves as a practical guide to matrix operations using the NumPy library. Understanding these functions is crucial for tasks involving linear algebra, scientific computing, and data analysis in Python. Proficiency in these functions not only paves the way for efficient and precise mathematical computations but also empowers individuals to solve real-world problems across diverse domains, from machine learning to engineering, with confidence and precision.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will explore a Python program that focuses on matrix operations using the NumPy library. NumPy provides extensive support for matrix-related operations, making it a powerful tool for linear algebra and&#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":[10333,28697,28626,28698,28699],"class_list":["post-123545","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-python-matrix-concepts","tag-python-practical","tag-python-program-on-matrix-concept","tag-work-on-matrix-using-numpy"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Program on Matrix Concepts - DataFlair<\/title>\n<meta name=\"description\" content=\"This Python program serves as a practical guide to matrix operations using the NumPy library. NumPy provides extensive support for matrix-related operations.\" \/>\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-matrix-concepts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Program on Matrix Concepts - DataFlair\" \/>\n<meta property=\"og:description\" content=\"This Python program serves as a practical guide to matrix operations using the NumPy library. NumPy provides extensive support for matrix-related operations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/\" \/>\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-04T06:23:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-28T06:33:12+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=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Program on Matrix Concepts - DataFlair","description":"This Python program serves as a practical guide to matrix operations using the NumPy library. NumPy provides extensive support for matrix-related operations.","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-matrix-concepts\/","og_locale":"en_US","og_type":"article","og_title":"Python Program on Matrix Concepts - DataFlair","og_description":"This Python program serves as a practical guide to matrix operations using the NumPy library. NumPy provides extensive support for matrix-related operations.","og_url":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-11-04T06:23:27+00:00","article_modified_time":"2024-02-28T06:33:12+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":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Python Program on Matrix Concepts","datePublished":"2023-11-04T06:23:27+00:00","dateModified":"2024-02-28T06:33:12+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/"},"wordCount":369,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["Python","python matrix concepts","python practical","python program on matrix concept","work on matrix using numpy"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/","url":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/","name":"Python Program on Matrix Concepts - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2023-11-04T06:23:27+00:00","dateModified":"2024-02-28T06:33:12+00:00","description":"This Python program serves as a practical guide to matrix operations using the NumPy library. NumPy provides extensive support for matrix-related operations.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-matrix-concepts\/#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 Matrix Concepts"}]},{"@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\/123545","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=123545"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123545\/revisions"}],"predecessor-version":[{"id":134148,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123545\/revisions\/134148"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=123545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=123545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=123545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}