{"id":4182,"date":"2020-09-26T20:43:50","date_gmt":"2020-09-26T15:13:50","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=4182"},"modified":"2021-06-14T15:00:25","modified_gmt":"2021-06-14T09:30:25","slug":"numpy-power","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/numpy-power\/","title":{"rendered":"Numpy Power | In-depth Explanation of np.power() With Examples"},"content":{"rendered":"\n<p>In this tutorial, we will learn about one of the essential numpy mathematical operations that you generally use in your&nbsp;data science&nbsp;and&nbsp;machine learning&nbsp;project. <strong>Numpy Power<\/strong> function is one of the advanced mathematical operations, which is very helpful in doing advanced projects. We will understand the syntaxes of power function through various kinds of examples and walk-throughs. <\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#What_is_Numpy_Power\" >What is Numpy Power?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#Numpy_Power_Syntax\" >Numpy Power Syntax<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#Parameters_of_Numpy_Power_Function\" >Parameters of Numpy Power Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#Return_Value_of_Numpy_Power\" >Return Value of Numpy Power<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#Examples_to_Learn_Working_of_Numpy_Power\" >Examples to Learn Working of Numpy Power<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#What_Will_Happen_When_an_Exponent_in_Numpy_Power_is_a_Negative_Number\" >What Will Happen When an Exponent in Numpy Power is a Negative Number<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#Is_There_a_Way_to_Use_Negative_Numbers_as_an_Exponent_in_Python_or_Numpy_Module\" >Is There a Way to Use Negative Numbers as an Exponent in Python or Numpy Module?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#Whats_Next\" >What&#8217;s Next?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_Numpy_Power\"><\/span>What is Numpy Power?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Numpy Power Function is a part of arithmetic functions in Numpy. Numpy power() is a function available in numpy in which the first element of the array is the base which is raised to the power element (second array) and finally returns the value.<em><strong>&nbsp;In layman language, what numpy power does is it calculates the exponentiation of value in Python.<\/strong><\/em><\/p>\n\n\n\n<p>I am assuming while writing this post that you already know about exponentiation. If not let me quickly explain you.<\/p>\n\n\n\n<p><strong>According to Wikipedia: <\/strong><a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Exponentiation#:~:text=Exponentiation%20is%20a%20mathematical%20operation,to%20the%20power%20of%20n%22.\" target=\"_blank\">Exponentiation<\/a>&nbsp;is a&nbsp;mathematical&nbsp;operation, written as&nbsp;bn, involving two numbers, the&nbsp;base&nbsp;b,&nbsp;and the&nbsp;<em>exponent<\/em>&nbsp;or&nbsp;<em>power<\/em>&nbsp;<em>n<\/em>, and pronounced as &#8220;<em>b<\/em>&nbsp;raised to the power of&nbsp;<em>n<\/em>&#8220;. When&nbsp;<em>n<\/em>&nbsp;is a positive&nbsp;integer, exponentiation corresponds to repeated&nbsp;multiplication&nbsp;of the base: that is,&nbsp;<em>b<\/em><sup><em>n<\/em><\/sup>&nbsp;is the&nbsp;product&nbsp;of multiplying&nbsp;<em>n<\/em>&nbsp;bases.<\/p>\n\n\n\n<p>Now I think you got a glance about exponentiation. So let&#8217;s move to our main topic and jump directly to the <strong>syntax&#8217;s of numpy.power.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Numpy_Power_Syntax\"><\/span>Numpy Power Syntax<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Basic High-Level (mostly used) syntax<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>np.power(array_of_base, array_of_exponent)<\/code><\/pre>\n\n\n\n<p>This is the basic numpy syntax which is widely used. <\/p>\n\n\n\n<p>However, <code>numpy.power()<\/code>is a universal function, i.e.&nbsp;it supports a several parameters that allow you to optimise its operation depending on the specifics of the algorithm in which we need it. The actual syntax of numpy.power() is the following.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>numpy.power(arr_of_base, arr_of_exp, out = None, where = True, casting = \u2018same_kind\u2019, order = \u2018K\u2019, dtype = None) <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parameters_of_Numpy_Power_Function\"><\/span><strong>Parameters<\/strong> of Numpy Power Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let&#8217;s move to the parameters of the <strong>numpy power<\/strong> function.<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-stripes\"><table><tbody><tr><td><strong>Parameter<\/strong><\/td><td><strong>Mandatory or Not<\/strong><\/td><\/tr><tr><td>arr_of_base<\/td><td>Mandatory<\/td><\/tr><tr><td>arr_of_exp<\/td><td>Mandatory<\/td><\/tr><tr><td>out<\/td><td>Not-Mandatory<\/td><\/tr><tr><td>where<\/td><td>Not-Mandatory<\/td><\/tr><tr><td>casting<\/td><td>Not-Mandatory<\/td><\/tr><tr><td>order<\/td><td>Not-Mandatory<\/td><\/tr><tr><td>dtype<\/td><td>Not-Mandatory<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">array_of_base: <\/h3>\n\n\n\n<p>These numbers will be utilised as the&#8221;foundations&#8221; of our exponents. Bear in mind which you can also just supply a single integer! The first parameter of this np.power function is<strong> array-of-bases<\/strong>. <\/p>\n\n\n\n<p>Note that this is needed. You must provide input here. Also, the item that you provide can take a variety of forms. It is possible to supply a NumPy array, but it is also possible to provide an array-like input. <\/p>\n\n\n\n<p>The array-like inputs which will work here are things such as a Python list, a Python tuple or one of the other Python objects that have array-like properties.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">array_of_exponent:<\/h3>\n\n\n\n<p>The second parameter is array-of-exponents, which lets you specify the exponents that you will apply to the bases, <strong>array-of-bases<\/strong>. <\/p>\n\n\n\n<p>Note that just like the array-of-bases input, this input must be a NumPy array or an array-like object. So here you are able to supply a NumPy array, a Python list, a tuple, or another Python object with array-like properties. You can even provide a single integer!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">out<\/h3>\n\n\n\n<p>Out is a ndarray (N- dimension array) and an optional field in <strong>numpy power<\/strong>. A place the result will be saved in. If given, the shape to which the inputs broadcast has to be in, when a freshly-allocated array is returned unless obtained or None. A tuple (possible as a keyword argument only) should have a length equal to the outputs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">where<\/h3>\n\n\n\n<p>This condition is transmitted over data. The out array will be set to an ufunc result in locations where the condition is True. The outside array will be maintaining its initial interest elsewhere. <\/p>\n\n\n\n<p>Notice when the default out = None produces an uninitialized out list, places within it where the condition is False will stay uninitialized.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Return_Value_of_Numpy_Power\"><\/span>Return Value of Numpy Power<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>The Numpy Power functionality treats elements in the very first input selection as a bottom and makes it raised into the power of the corresponding component of the 2nd input array.&nbsp;<\/strong><\/p>\n\n\n\n<p>In other words, the NumPy power() function returns an array with components of the first range raised to the second array&#8217;s power segment. The result will probably be in integer form.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Examples_to_Learn_Working_of_Numpy_Power\"><\/span>Examples to Learn Working of Numpy Power<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before you run the code, you will have to run a little bit of code first. <\/p>\n\n\n\n<p>You essentially have to import NumPy and give it an&#8221;alias.&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example 1: Basic Example to Raise Power<\/h3>\n\n\n\n<p>To begin with, we are going to work with a really simple illustration.<\/p>\n\n\n\n<p>Here, we are just going to raise an integer into an average power.<\/p>\n\n\n\n<p>To do this, we&#8217;ll predict the NumPy power work together with the code np.power(). Then inside of the parenthesis, we&#8217;ll supply two arguments. The bottom and the exponent.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\ny = np.power(4,2)\nprint(y)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>16<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Explanation:<\/h4>\n\n\n\n<p>This is quite straightforward. It merely computes 4 to the 2nd power that equals 16.<\/p>\n\n\n\n<p>Notice the way the inputs get the job done. The primary enter (4 ) is that the foundation and the next argument (2 ) is that the exponent.<\/p>\n\n\n\n<p>This is precisely the way the remaining cases will do the job.<\/p>\n\n\n\n<p>Let us look at a more complex case.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 2: Calculating Exponents of an Array of Numbers<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport numpy as np \na = np.array(&#x5B;5,50,100]) \n\nprint('Original Array is:') \nprint(a) \nprint('\\n')  \n\nprint('After Calculating Exponents Array:') \nprint(np.power(a,2)) \n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Original Array is:\n&#91;  5  50 100]\n\n\nAfter Calculating Exponents Array:\n&#91;   25  2500 10000]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Explanation<\/strong><\/h4>\n\n\n\n<p>Here in this example we are calculating exponent of an array instead of the base being a single integer. Here array meaning the base will be a group of numbers organized into an array (i.e., a Python list).<\/p>\n\n\n\n<p>So, here  in this case the base a simple list of numbers which are <strong>[5, 50, 100]<\/strong>. In the above example <strong>np.power() <\/strong>has two inputs <strong>(a,2)<\/strong>. Therefore, a will be the list of elements which is base <strong>[5, 50, 100]<\/strong> and <strong>2<\/strong> will be the power to be raised by elements present in array <strong>&#8216;a&#8217;.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 3: Using Numpy power When Both Base and Exponents are Arrays<\/h3>\n\n\n\n<p>Let&#8217;s see what will happen when both the base and the exponents are arrays which means instead of one input as array we will take <strong>both of the inputs are arrays<\/strong>.<\/p>\n\n\n\n<p>Always keep in mind we are using lists because there is nothing like array in Python. Moving forward to the example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\n#Declaring a and b\na = &#x5B;3, 5, 7, 9, 11]\nb = &#x5B;0, 1, 2, 3, 4]\n\nprint(&quot;Elements of a raised to the power elements of b are: &quot;)\nprint(np.power(a, b))\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;    1     5    49   729  14641]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Explanation<\/strong><\/h4>\n\n\n\n<p>In the above example 3 we have declared two arrays (lists) naming <strong>&#8216;a&#8217; <\/strong>and <strong>&#8216;b&#8217;<\/strong>. The array <strong>&#8216;a&#8217;<\/strong> consists of elements <strong>[3, 5, 7, 9, 11]<\/strong> and array <strong>&#8216;b&#8217;<\/strong> consists of <strong>[0, 1, 2, 3, 4]<\/strong> respectively. Here the first array <strong>&#8216;a&#8217;<\/strong> is going to be the array of bases, and the second array <strong>&#8216;b&#8217;<\/strong> will be the list of exponents. After that we have calculated the  result of <strong>&#8216;a&#8217;<\/strong> to the power <strong>&#8216;b&#8217;<\/strong> with the help of <strong>np.power()<\/strong> function. So the calculation should go like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">np.power([[3, 5, 7, 9, 11], [0, 1, 2, 3, 4]) =  [ 1   5   49   729    14641]<\/pre>\n\n\n\n<p><strong>Note:<\/strong> The shape of both the arrays should be same.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 4: Using Numpy Power to calculate exponents with multi-dimensional numpy array<\/h3>\n\n\n\n<p>In this example we will learn how to calculate exponents of a two dimensional base array with the help of <strong>np.power()<\/strong> function. Also the value of exponent will be an array.<\/p>\n\n\n\n<p>Let&#8217;s jump directly into the examples and then understand how the things are working. It will be more easy for you to learn through example<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport numpy as np\n\na = np.array(&#x5B;&#x5B;0,1,2,3,4],&#x5B;4,3,2,1,0],&#x5B;4,0,1,2,3],&#x5B;3,4,0,1,2]])\nb = &#x5B;2, 2, 2, 2, 2]\nprint(np.power(a,b))\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;&#91; 0  1  4  9 16]\n &#91;16  9  4  1  0]\n &#91;16  0  1  4  9]\n &#91; 9 16  0  1  4]]<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>Let&#8217;s breakdown things to make it easy for a beginner. As we know we are using numpy so first we have imported the numpy library as np. After that we have created a 2-D numpy array with the help of <strong>np.array()<\/strong> function and stored the array in variable <strong>&#8216;a&#8217;<\/strong>. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = np.array([[0,1,2,3,4],[4,3,2,1,0],[4,0,1,2,3],[3,4,0,1,2]])\nprint(a)<\/pre>\n\n\n\n<p>Let&#8217;s print this to make it clear for you guys<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;&#91;0 1 2 3 4]\n &#91;4 3 2 1 0]\n &#91;4 0 1 2 3]\n &#91;3 4 0 1 2]]<\/code><\/pre>\n\n\n\n<p>This is a fairly simple 2-d NumPy array as you can see.<\/p>\n\n\n\n<p>Now, let\u2019s apply np.power() function on this 2d numpy array with our exponents as [2, 2, 2, 2] and print it out. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(np.power(a, &#91;2, 2, 2, 2]))<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;&#91; 0  1  4  9 16]\n &#91;16  9  4  1  0]\n &#91;16  0  1  4  9]\n &#91; 9 16  0  1  4]]<\/code><\/pre>\n\n\n\n<p>As we know np.power() function takes two arguments the first argument \u2013 the array of bases \u2013 is a 2-d array. The second argument \u2013 the exponents \u2013 is a 1-d array. Both have the same number of columns which is <strong>&#8216;5&#8217;<\/strong>. So, what happens here is NumPy power applies the exponents to&nbsp;<em>every row<\/em> and gives us the result.<\/p>\n\n\n\n<p><strong>This is also known as broadcasting.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Will_Happen_When_an_Exponent_in_Numpy_Power_is_a_Negative_Number\"><\/span>What Will Happen When an Exponent in Numpy Power is a Negative Number<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Keeping it simple <strong>you will get a value error<\/strong> if the exponent is a negative number<\/p>\n\n\n\n<p>Let&#8217;s see it through an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\n#Declaring a and b\na = &#x5B;3, 5, 7, 9, 11]\nb = &#x5B;0, -1, 2, 3, 4]\n\nprint(&quot;Elements of a raised to the power elements of b are: &quot;)\nprint(np.power(a, b))\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(np.power(a, b))\nValueError: Integers to negative integer powers are not allowed.<\/code><\/pre>\n\n\n\n<p>Here in this example we can see there is a negative number <strong>&#8216;-1&#8217;<\/strong> in the exponent array <strong>b.<\/strong> So we can&#8217;t get our desired result. The <a href=\"http:\/\/www.pythonpool.com\/is-python-compiled-interpreted-or-both\/\" >Python interpreter<\/a> will show a value error saying  <strong>Integers to negative integer powers are not allowed.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Is_There_a_Way_to_Use_Negative_Numbers_as_an_Exponent_in_Python_or_Numpy_Module\"><\/span>Is There a Way to Use Negative Numbers as an Exponent in Python or Numpy Module?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Yes, you can use numpy.float_power()  to use negative numbers as an exponent.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Whats_Next\"><\/span>What&#8217;s Next?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>NumPy is very powerful, and incredibly essential for information science in Python. That being true, if you are interested in <a href=\"http:\/\/www.pythonpool.com\/data-science-internship\/\" >data science<\/a> in Python, you really ought to find out more about Python.<\/p>\n\n\n\n<p>You might like our following tutorials on numpy.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.pythonpool.com\/numpy-mean\/\">Numpy Mean: Implementation and Importance<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/numpy-random\/\">Using Numpy Random Function to Create Random Data<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/numpy-reshape\/\">NumPy Reshape: Reshaping Arrays With Ease<\/a><\/li><\/ul>\n\n\n\n<p><strong>Reference:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/docs.scipy.org\/doc\/numpy-1.13.0\/reference\/generated\/numpy.power.html#numpy.power\" target=\"_blank\" rel=\"noreferrer noopener\">Official Documentation<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The <strong>numpy power()<\/strong> function computes exponents in Numpy. It enables us to perform both simple exponentiation like a to the power of b, and can also perform same computation on large numpy arrays also.<\/p>\n\n\n\n<p>If you still have any questions regarding NumPy power function?<\/p>\n\n\n\n<p>Leave your question in the comments below.<\/p>\n\n\n\n<p><strong><em>Happy Pythonning!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will learn about one of the essential numpy mathematical operations that you generally use in your&nbsp;data science&nbsp;and&nbsp;machine learning&nbsp;project. Numpy Power function &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Numpy Power | In-depth Explanation of np.power() With Examples\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/numpy-power\/#more-4182\" aria-label=\"More on Numpy Power | In-depth Explanation of np.power() With Examples\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":4447,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1495],"tags":[2230,2220,2222,2227,2233,2224,2234,2229,2232,2221,2228,2226,2225,2223,2231,652],"class_list":["post-4182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy","tag-element-wise-power-numpy","tag-matrix-power-numpy","tag-numpy-element-wise-power","tag-numpy-elementwise-power","tag-numpy-matrix-element-wise-power","tag-numpy-matrix-power","tag-numpy-power","tag-numpy-power-function","tag-numpy-power-of-2","tag-numpy-power-vs","tag-numpy-raise-matrix-to-power","tag-numpy-raise-to-power","tag-power-in-numpy","tag-power-numpy","tag-power-python-numpy","tag-python-numpy-power","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Numpy Power | In-depth Explanation of np.power() With Examples<\/title>\n<meta name=\"description\" content=\"Numpy power is a function available in numpy in which the first element of the array is the base which is raised to the power element.\" \/>\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.pythonpool.com\/numpy-power\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Numpy Power | In-depth Explanation of np.power() With Examples\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we will learn about one of the essential numpy mathematical operations that you generally use in your&nbsp;data\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/numpy-power\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-26T15:13:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-14T09:30:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Python Pool\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Python Pool\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/\"},\"author\":{\"name\":\"Python Pool\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\"},\"headline\":\"Numpy Power | In-depth Explanation of np.power() With Examples\",\"datePublished\":\"2020-09-26T15:13:50+00:00\",\"dateModified\":\"2021-06-14T09:30:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/\"},\"wordCount\":1579,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png\",\"keywords\":[\"element wise power numpy\",\"matrix power numpy\",\"numpy element wise power\",\"numpy elementwise power\",\"numpy matrix element wise power\",\"numpy matrix power\",\"numpy power\",\"numpy power function\",\"numpy power of 2\",\"numpy power vs **\",\"numpy raise matrix to power\",\"numpy raise to power\",\"power in numpy\",\"power numpy\",\"power python numpy\",\"python numpy power\"],\"articleSection\":[\"Numpy\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/numpy-power\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/\",\"url\":\"https:\/\/www.pythonpool.com\/numpy-power\/\",\"name\":\"Numpy Power | In-depth Explanation of np.power() With Examples\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png\",\"datePublished\":\"2020-09-26T15:13:50+00:00\",\"dateModified\":\"2021-06-14T09:30:25+00:00\",\"description\":\"Numpy power is a function available in numpy in which the first element of the array is the base which is raised to the power element.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/numpy-power\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png\",\"width\":1350,\"height\":650,\"caption\":\"numpy power\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/numpy-power\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Numpy Power | In-depth Explanation of np.power() With Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\",\"name\":\"Python Pool\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"caption\":\"Python Pool\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Numpy Power | In-depth Explanation of np.power() With Examples","description":"Numpy power is a function available in numpy in which the first element of the array is the base which is raised to the power element.","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.pythonpool.com\/numpy-power\/","og_locale":"en_US","og_type":"article","og_title":"Numpy Power | In-depth Explanation of np.power() With Examples","og_description":"In this tutorial, we will learn about one of the essential numpy mathematical operations that you generally use in your&nbsp;data","og_url":"https:\/\/www.pythonpool.com\/numpy-power\/","og_site_name":"Python Pool","article_published_time":"2020-09-26T15:13:50+00:00","article_modified_time":"2021-06-14T09:30:25+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png","type":"image\/png"}],"author":"Python Pool","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Python Pool","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/numpy-power\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/numpy-power\/"},"author":{"name":"Python Pool","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998"},"headline":"Numpy Power | In-depth Explanation of np.power() With Examples","datePublished":"2020-09-26T15:13:50+00:00","dateModified":"2021-06-14T09:30:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/numpy-power\/"},"wordCount":1579,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png","keywords":["element wise power numpy","matrix power numpy","numpy element wise power","numpy elementwise power","numpy matrix element wise power","numpy matrix power","numpy power","numpy power function","numpy power of 2","numpy power vs **","numpy raise matrix to power","numpy raise to power","power in numpy","power numpy","power python numpy","python numpy power"],"articleSection":["Numpy"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/numpy-power\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/numpy-power\/","url":"https:\/\/www.pythonpool.com\/numpy-power\/","name":"Numpy Power | In-depth Explanation of np.power() With Examples","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png","datePublished":"2020-09-26T15:13:50+00:00","dateModified":"2021-06-14T09:30:25+00:00","description":"Numpy power is a function available in numpy in which the first element of the array is the base which is raised to the power element.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/numpy-power\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/numpy-power\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/numpy-power\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/09\/Theatre-Actor-Portfolio-Website-2.png","width":1350,"height":650,"caption":"numpy power"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/numpy-power\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Numpy Power | In-depth Explanation of np.power() With Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998","name":"Python Pool","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","caption":"Python Pool"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/4182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=4182"}],"version-history":[{"count":16,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/4182\/revisions"}],"predecessor-version":[{"id":13485,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/4182\/revisions\/13485"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/4447"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=4182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=4182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=4182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}