

{"id":79318,"date":"2020-07-25T20:39:15","date_gmt":"2020-07-25T15:09:15","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=79318"},"modified":"2021-05-09T13:13:33","modified_gmt":"2021-05-09T07:43:33","slug":"numpy-arithmetic-operations","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/","title":{"rendered":"NumPy Arithmetic Operations and Functions"},"content":{"rendered":"<p>Python has a wide range of standard arithmetic operations. These operations help perform normal functions of addition, subtraction, multiplication, and divisions. There are specific functions in NumPy for performing arithmetic operations. Let us learn about these NumPy Arithmetic Operations and Functions.<\/p>\n<h2><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79804\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg\" alt=\"NumPy Arithmetic Operations and Functions\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/h2>\n<h2>NumPy Arithmetic Operations<\/h2>\n<p>Arithmetic operations are possible only if the array has the same structure and dimensions. We carry out the operations following the rules of array manipulation. We have both functions and operators to perform these functions.<\/p>\n<h3>NumPy Add function<\/h3>\n<p>This function is used to add two arrays. If we add arrays having dissimilar shapes we get \u201cValue Error\u201d.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([10,20,100,200,500])\r\nb = np.array([3,4,5,6,7])\r\nnp.add(a, b)\r\n \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([ 13, 24, 105, 206, 507])<\/div>\n<h3>NumPy Add Operator<\/h3>\n<p>We can also use the add operator \u201c+\u201d to perform addition of two arrays.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([10,20,100,200,500])\r\nb = np.array([3,4,5,6,7])\r\nprint(a+b)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[ 13 24 105 206 507]<\/div>\n<h3>NumPy Subtract function<\/h3>\n<p>We use this function to output the difference of two arrays. If we subtract two arrays having dissimilar shapes we get \u201cValue Error\u201d.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([10,20,100,200,500])\r\nb = np.array([3,4,5,6,7])\r\nnp.subtract(a, b)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([ 7, 16, 95, 194, 493])<\/div>\n<h3>NumPy Subtract Operator<\/h3>\n<p>We can also use the subtract operator \u201c-\u201d to produce the difference of two arrays.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([10,20,100,200,500])\r\nb = np.array([3,4,5,6,7])\r\nprint(a-b)\r\n \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[ 7 16 95 194 493]<\/div>\n<h3>NumPy Multiply function<\/h3>\n<p>We use this function to output the multiplication of two arrays. We cannot work with dissimilar arrays.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nb = np.array([3,4,5,6,7])\r\nnp.multiply(a, b)\r\n \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([21, 12, 20, 30, 7])<\/div>\n<h3>NumPy Multiply Operator<\/h3>\n<p>We can also use the multiplication operator \u201c*\u201d to get the product of two arrays.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nb = np.array([3,4,5,6,7])\r\nprint(a*b<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[21 12 20 30 7]<\/div>\n<h2>NumPy Divide Function<\/h2>\n<p>We use this function to output the division of two arrays. We cannot divide dissimilar arrays.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nb = np.array([3,4,5,6,7])\r\nnp.divide(a,b)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([2.33333333, 0.75 , 0.8 , 0.83333333, 0.14285714])<\/div>\n<h3>NumPy Divide Operator<\/h3>\n<p>We can also use the divide operator \u201c\/\u201d to divide two arrays.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nb = np.array([3,4,5,6,7])\r\nprint(a\/b)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[2.33333333 0.75 0.8 0.83333333 0.14285714]<\/div>\n<h3>NumPy Mod and Remainder function<\/h3>\n<p>We use both the functions to output the remainder of the division of two arrays.<\/p>\n<h4>NumPy Remainder Function<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nb = np.array([3,4,5,6,7])\r\nnp.remainder(a,b)\r\n \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([1, 3, 4, 5, 1])<\/div>\n<h4>NumPy Mod Function<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nb = np.array([3,4,5,6,7])\r\nnp.mod(a,b)\r\n \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([1, 3, 4, 5, 1])<\/div>\n<h2>NumPy Power Function<\/h2>\n<p>This Function treats the first array as base and raises it to the power of the elements of the second array.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nb = np.array([3,4,5,6,7])\r\nnp.power(a,b)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([ 343, 81, 1024, 15625, 1])<\/div>\n<h2>NumPy Reciprocal Function<\/h2>\n<p>This Function returns the reciprocal of all the array elements.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\na = np.array([7,3,4,5,1])\r\nnp.reciprocal(a)\r\n \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array([0, 0, 0, 0, 1])<\/div>\n<h2>Summary<\/h2>\n<p>There are additional functions to perform Numpy arithmetic operations on array elements. This is an addition to the inbuilt standard python functions. We need to follow a few rules of array manipulation for performing these operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python has a wide range of standard arithmetic operations. These operations help perform normal functions of addition, subtraction, multiplication, and divisions. There are specific functions in NumPy for performing arithmetic operations. Let us learn&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":79804,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22401],"tags":[3491,22779,22777,22775,22776,22778,22780,22781],"class_list":["post-79318","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy","tag-data-types-in-numpy","tag-numpy-addition-function","tag-numpy-arithmetic-functions","tag-numpy-arithmetic-operations","tag-numpy-arithmetic-operators","tag-numpy-multiplication","tag-numpy-power-function","tag-numpy-reciprocal-function"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>NumPy Arithmetic Operations and Functions - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about NumPy Arithmetic Operations and Functions like addition, subtraction, Remainder and Mod, Division, Power, Reciprocal, etc with examples\" \/>\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\/numpy-arithmetic-operations\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NumPy Arithmetic Operations and Functions - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about NumPy Arithmetic Operations and Functions like addition, subtraction, Remainder and Mod, Division, Power, Reciprocal, etc with examples\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/\" \/>\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=\"2020-07-25T15:09:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-09T07:43:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\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":"NumPy Arithmetic Operations and Functions - DataFlair","description":"Learn about NumPy Arithmetic Operations and Functions like addition, subtraction, Remainder and Mod, Division, Power, Reciprocal, etc with examples","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\/numpy-arithmetic-operations\/","og_locale":"en_US","og_type":"article","og_title":"NumPy Arithmetic Operations and Functions - DataFlair","og_description":"Learn about NumPy Arithmetic Operations and Functions like addition, subtraction, Remainder and Mod, Division, Power, Reciprocal, etc with examples","og_url":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-07-25T15:09:15+00:00","article_modified_time":"2021-05-09T07:43:33+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg","type":"image\/jpeg"}],"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\/numpy-arithmetic-operations\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"NumPy Arithmetic Operations and Functions","datePublished":"2020-07-25T15:09:15+00:00","dateModified":"2021-05-09T07:43:33+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/"},"wordCount":356,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg","keywords":["Data Types in NumPy","Numpy addition function","Numpy Arithmetic functions","NumPy Arithmetic Operations","NumPy Arithmetic Operators","Numpy Multiplication","NumPy Power Function","NumPy Reciprocal Function"],"articleSection":["NumPy Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/","url":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/","name":"NumPy Arithmetic Operations and Functions - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg","datePublished":"2020-07-25T15:09:15+00:00","dateModified":"2021-05-09T07:43:33+00:00","description":"Learn about NumPy Arithmetic Operations and Functions like addition, subtraction, Remainder and Mod, Division, Power, Reciprocal, etc with examples","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/NumPy-Arithmetic-Operators-Functions.jpg","width":1200,"height":628,"caption":"NumPy Arithmetic Operations and Functions"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/numpy-arithmetic-operations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"NumPy Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/numpy\/"},{"@type":"ListItem","position":3,"name":"NumPy Arithmetic Operations and Functions"}]},{"@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\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/79318","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\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=79318"}],"version-history":[{"count":2,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/79318\/revisions"}],"predecessor-version":[{"id":79805,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/79318\/revisions\/79805"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/79804"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=79318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=79318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=79318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}