{"id":4022,"date":"2023-10-24T15:50:50","date_gmt":"2023-10-24T10:20:50","guid":{"rendered":"https:\/\/python-programs.com\/?p=4022"},"modified":"2023-11-10T11:57:36","modified_gmt":"2023-11-10T06:27:36","slug":"python-programming-basic-operations","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-programming-basic-operations\/","title":{"rendered":"Python Programming \u2013 Basic Operations"},"content":{"rendered":"

In this Page, We are Providing Python Programming \u2013 Basic Operations. Students can visit for more Detail and Explanation of Python Handwritten Notes<\/a>\u00a0Pdf.<\/p>\n

Python Programming \u2013 Basic Operations<\/h2>\n

Basic Operations<\/strong><\/p>\n

Arithmetic operations when applied on NumPy arrays, they are implemented element-wise.<\/p>\n

>>> a=np . array ( [ 20 , 30 , 40 , 50 ] )\r\n>>> b=np . arange ( 4 ) \r\n>>> c=a - b \r\n>>> c\r\narray ( [ 20 , 29 , 38 , 47 ] )\r\n>>> b**2\r\narray ( [ 0 , 1 , 4 , 9 ] )\r\n>>> a<39\r\narray ( [ True , True , False , False ] , dtype=bool )<\/pre>\n

The product operator * operates element-wise in NumPy arrays. The matrix product can be performed using the dot ( ) function or creating matrix objects (refer section 7.8).<\/p>\n

>>> a=np . array ( [ [ 1 , 1 ] ,\r\n. . . [ 0 , 1 ] ] )\r\n>>> b=np . array ( [ [ 2 , 0 ] ,\r\n. . . [ 3 , 4 ] ] )\r\n>>> a*b \r\narray ( [ [ 2 , 0 ] ,\r\n[ 0 , 4 ] ] )\r\n>>> np . dot ( a , b ) \r\narray ( [ [ 5 , 4 ] ,\r\n[ 3 , 4 ] ] )<\/pre>\n

Some operations, such as +=, *=, etc., modifies an existing array, rather than creating a new array.<\/p>\n

>>> a=np . array ( [ [ 1 , 2 ] ,                        # a is integer type\r\n. . . [ 3 , 4 ] ] )\r\n>>> b=np . array ( [ [ 1 . , 2 . ] ,                   # b is float type\r\n. . . [ 3 . , 4 . ] ] )\r\n>>> a*=2 \r\n>>> a\r\narray ( [ [ 2 , 4 ] ,\r\n[ 6 , 8 ] ] )\r\n>>> b+=a \r\n>>> b\r\narray ( [ [ 3 . , 6 . ] ,\r\n[ 9 . , 12 . ] ] )\r\n>>> a+=b                                                  # b is converted to integer type\r\n>>> a\r\narray ( [ [ 5 , 10 ] ,\r\n[ 15 , 20 ] ] )<\/pre>\n

When operating with arrays of different types, the type of the resulting array corresponds to the more general or precise one (a behavior known as “upcasting”).<\/p>\n

>>> a=np . array ( [ 1 . 1 , 2 . 2 , 3 . 3 ] )\r\n>>> a . dtype . name\r\n' float64 ' \r\n>>> b=np . array ( [ 4 , 5 , 6 ] )\r\n>>> b . dtype . name ' int32 '\r\n>>> c=a+b \r\n>>> c\r\narray 0( [ 5 . 1 , 7 . 2 , 9 . 3 ] )\r\n>>> c . dtype . name ' float64 '<\/pre>\n

Many unary operations, such as computing the sum of all the elements in the array, are implemented as methods of the ndarray class .<\/p>\n

>>> a=np . array ( [ [5 , 8 ] ,\r\n. . . [ 3 , 6 ] ] )\r\n>>> a . sum ( )\r\n22\r\n>>> a . min ( )\r\n3\r\n>>> a . max ( )\r\n8<\/pre>\n

By default, these operations apply to the array as though it were a list of numbers, regardless of its shape. However, by specifying the axis parameter you can apply an operation along the specified axis of an array:<\/p>\n

>>> a=np . arange ( 12 ) . reshape ( 3 , 4 )\r\n>>> a\r\narray ( [ [ 0 , 1 , 2 , 3 ] ,\r\n[ 4 , 5 , 6 , 7 ] ,\r\n[ 8 , 9 , 10 , 11 ] ] )\r\n>>> a.sum(axis=0)                                             # Sum of each column\r\narray ( [12, 15, 18, 21] )\r\n>>> a.min(axis=1)                                             # Minimum of each now\r\narray ( [ 0 , 4 , 8 ] )\r\n>>> a . cumsum ( axis=1 )                                  # Cumulative sum along each now\r\narray ( [ [ 0 , 1 , 3 , 6 ] ,\r\n[ 4 , 9 , 15 , 22 ] ,\r\n[ 8 , 17 , 27 , 38 ] ] )<\/pre>\n","protected":false},"excerpt":{"rendered":"

In this Page, We are Providing Python Programming \u2013 Basic Operations. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Python Programming \u2013 Basic Operations Basic Operations Arithmetic operations when applied on NumPy arrays, they are implemented element-wise. >>> a=np . array ( [ 20 , 30 , 40 , 50 ] …<\/p>\n

Python Programming \u2013 Basic Operations<\/span> Read More »<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[],"yoast_head":"\nPython Programming \u2013 Basic Operations - Python Programs<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/python-programs.com\/python-programming-basic-operations\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Programming \u2013 Basic Operations - Python Programs\" \/>\n<meta property=\"og:description\" content=\"In this Page, We are Providing Python Programming \u2013 Basic Operations. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Python Programming \u2013 Basic Operations Basic Operations Arithmetic operations when applied on NumPy arrays, they are implemented element-wise. >>> a=np . array ( [ 20 , 30 , 40 , 50 ] … Python Programming \u2013 Basic Operations Read More »\" \/>\n<meta property=\"og:url\" content=\"https:\/\/python-programs.com\/python-programming-basic-operations\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Programs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/btechgeeks\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-24T10:20:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-10T06:27:36+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@btech_geeks\" \/>\n<meta name=\"twitter:site\" content=\"@btech_geeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prasanna\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/python-programs.com\/#organization\",\"name\":\"BTech Geeks\",\"url\":\"https:\/\/python-programs.com\/\",\"sameAs\":[\"https:\/\/www.instagram.com\/btechgeeks\/\",\"https:\/\/www.linkedin.com\/in\/btechgeeks\",\"https:\/\/in.pinterest.com\/btechgeek\/\",\"https:\/\/www.youtube.com\/channel\/UC9MlCqdJ3lKqz2p5114SDIg\",\"https:\/\/www.facebook.com\/btechgeeks\",\"https:\/\/twitter.com\/btech_geeks\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png\",\"contentUrl\":\"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png\",\"width\":350,\"height\":70,\"caption\":\"BTech Geeks\"},\"image\":{\"@id\":\"https:\/\/python-programs.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/python-programs.com\/#website\",\"url\":\"https:\/\/python-programs.com\/\",\"name\":\"Python Programs\",\"description\":\"Python Programs with Examples, How To Guides on Python\",\"publisher\":{\"@id\":\"https:\/\/python-programs.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/python-programs.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/python-programs.com\/python-programming-basic-operations\/#webpage\",\"url\":\"https:\/\/python-programs.com\/python-programming-basic-operations\/\",\"name\":\"Python Programming \u2013 Basic Operations - Python Programs\",\"isPartOf\":{\"@id\":\"https:\/\/python-programs.com\/#website\"},\"datePublished\":\"2023-10-24T10:20:50+00:00\",\"dateModified\":\"2023-11-10T06:27:36+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/python-programs.com\/python-programming-basic-operations\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/python-programs.com\/python-programming-basic-operations\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/python-programs.com\/python-programming-basic-operations\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/python-programs.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Programming \u2013 Basic Operations\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/python-programs.com\/python-programming-basic-operations\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/python-programs.com\/python-programming-basic-operations\/#webpage\"},\"author\":{\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb\"},\"headline\":\"Python Programming \u2013 Basic Operations\",\"datePublished\":\"2023-10-24T10:20:50+00:00\",\"dateModified\":\"2023-11-10T06:27:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/python-programs.com\/python-programming-basic-operations\/#webpage\"},\"wordCount\":170,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/python-programs.com\/#organization\"},\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/python-programs.com\/python-programming-basic-operations\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb\",\"name\":\"Prasanna\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g\",\"caption\":\"Prasanna\"},\"url\":\"https:\/\/python-programs.com\/author\/prasanna\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Programming \u2013 Basic Operations - Python Programs","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:\/\/python-programs.com\/python-programming-basic-operations\/","og_locale":"en_US","og_type":"article","og_title":"Python Programming \u2013 Basic Operations - Python Programs","og_description":"In this Page, We are Providing Python Programming \u2013 Basic Operations. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Python Programming \u2013 Basic Operations Basic Operations Arithmetic operations when applied on NumPy arrays, they are implemented element-wise. >>> a=np . array ( [ 20 , 30 , 40 , 50 ] … Python Programming \u2013 Basic Operations Read More »","og_url":"https:\/\/python-programs.com\/python-programming-basic-operations\/","og_site_name":"Python Programs","article_publisher":"https:\/\/www.facebook.com\/btechgeeks","article_published_time":"2023-10-24T10:20:50+00:00","article_modified_time":"2023-11-10T06:27:36+00:00","twitter_card":"summary_large_image","twitter_creator":"@btech_geeks","twitter_site":"@btech_geeks","twitter_misc":{"Written by":"Prasanna","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/python-programs.com\/#organization","name":"BTech Geeks","url":"https:\/\/python-programs.com\/","sameAs":["https:\/\/www.instagram.com\/btechgeeks\/","https:\/\/www.linkedin.com\/in\/btechgeeks","https:\/\/in.pinterest.com\/btechgeek\/","https:\/\/www.youtube.com\/channel\/UC9MlCqdJ3lKqz2p5114SDIg","https:\/\/www.facebook.com\/btechgeeks","https:\/\/twitter.com\/btech_geeks"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/python-programs.com\/#\/schema\/logo\/image\/","url":"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png","contentUrl":"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png","width":350,"height":70,"caption":"BTech Geeks"},"image":{"@id":"https:\/\/python-programs.com\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/python-programs.com\/#website","url":"https:\/\/python-programs.com\/","name":"Python Programs","description":"Python Programs with Examples, How To Guides on Python","publisher":{"@id":"https:\/\/python-programs.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/python-programs.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/python-programs.com\/python-programming-basic-operations\/#webpage","url":"https:\/\/python-programs.com\/python-programming-basic-operations\/","name":"Python Programming \u2013 Basic Operations - Python Programs","isPartOf":{"@id":"https:\/\/python-programs.com\/#website"},"datePublished":"2023-10-24T10:20:50+00:00","dateModified":"2023-11-10T06:27:36+00:00","breadcrumb":{"@id":"https:\/\/python-programs.com\/python-programming-basic-operations\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/python-programs.com\/python-programming-basic-operations\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/python-programs.com\/python-programming-basic-operations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/python-programs.com\/"},{"@type":"ListItem","position":2,"name":"Python Programming \u2013 Basic Operations"}]},{"@type":"Article","@id":"https:\/\/python-programs.com\/python-programming-basic-operations\/#article","isPartOf":{"@id":"https:\/\/python-programs.com\/python-programming-basic-operations\/#webpage"},"author":{"@id":"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb"},"headline":"Python Programming \u2013 Basic Operations","datePublished":"2023-10-24T10:20:50+00:00","dateModified":"2023-11-10T06:27:36+00:00","mainEntityOfPage":{"@id":"https:\/\/python-programs.com\/python-programming-basic-operations\/#webpage"},"wordCount":170,"commentCount":0,"publisher":{"@id":"https:\/\/python-programs.com\/#organization"},"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/python-programs.com\/python-programming-basic-operations\/#respond"]}]},{"@type":"Person","@id":"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb","name":"Prasanna","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/python-programs.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g","caption":"Prasanna"},"url":"https:\/\/python-programs.com\/author\/prasanna\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/4022"}],"collection":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/comments?post=4022"}],"version-history":[{"count":1,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/4022\/revisions"}],"predecessor-version":[{"id":4024,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/4022\/revisions\/4024"}],"wp:attachment":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/media?parent=4022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/categories?post=4022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/tags?post=4022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}