{"id":39862,"date":"2023-01-30T08:45:23","date_gmt":"2023-01-30T08:45:23","guid":{"rendered":"https:\/\/www.askpython.com\/?p=39862"},"modified":"2023-02-18T15:43:15","modified_gmt":"2023-02-18T15:43:15","slug":"numpy-i0","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python-modules\/numpy\/numpy-i0","title":{"rendered":"How to Use Numpy i0 in Python?"},"content":{"rendered":"\n<p>This article will talk about the Numpy i0 function. <strong>The year was 1817.<\/strong> It was a fine evening when a German astronomer by the name of <em>Friedrich Wilhelm Bessel<\/em> was taking a closer look at the movement of planets. Well, what else could he have referred to rather than the most advanced source available around that time \u2013 <em>Kepler\u2019s equations of planetary motion<\/em>!<em> <\/em>While he went deep into investigating those equations, it was only a matter of time before he, himself discovered something.<\/p>\n\n\n\n<p>An equation that explains the motion of fluids around a cylinder. Thus was born <em>Bessel\u2019s equation. <\/em>In the later years, it will be used to provide mathematical solutions to the problems involving,<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The flow of heat in a solid cylinder<\/li>\n\n\n\n<li>The flow of electric current in a solid cylinder<\/li>\n\n\n\n<li>The motion of electromagnetic waves around a wire<\/li>\n\n\n\n<li>Deformation in an elastic body<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"105\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/The-Bessels-Equation.jpg\" alt=\"The Bessels Equation\" class=\"wp-image-40009\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/The-Bessels-Equation.jpg 470w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/The-Bessels-Equation-300x67.jpg 300w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><figcaption class=\"wp-element-caption\">The Bessel&#8217;s Equation<\/figcaption><\/figure>\n\n\n\n<p>When the above differential equation is solved, it results in <em>Bessel\u2019s function<\/em>. Saving us from the tedious task of deriving the results through each step, Python helps us to jump straight to the results through an exclusive function \u2013 the numpy.i0 (i-zero; not \u2018o\u2019). This is a modified form of <em>Bessel\u2019s function <\/em>that is of the first kind and orders zero. <\/p>\n\n\n\n<p>We would be exploring this very function in this article, but before that, there is something that needs to be done. Importing the <em>numpy <\/em>library. The following code can be used to serve the purpose.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n<\/pre><\/div>\n\n\n<p>Thereafter, we shall explore further the&nbsp;<em>numpy.i0( )&nbsp;<\/em>function through each of the following sections.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Syntax of\u00a0the<\/strong> <strong><em>Numpy i0\u00a0<\/em>function<\/strong><\/li>\n\n\n\n<li><strong>Using <em>Numpy i0 <\/em>on N-Dimensional Arrays<\/strong><\/li>\n\n\n\n<li><strong>Creating plots for <em>Numpy i0 <\/em>results<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax of\u00a0the Numpy i0\u00a0function<\/h2>\n\n\n\n<p>The syntax of this function is pretty straightforward and is given below. Mathematically <em>Bessel\u2019s function <\/em>of the first kind, order zero is denoted by I<sub>0<\/sub>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nnumpy.i0(x)\n<\/pre><\/div>\n\n\n<p>where,<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>x \u2013 <\/em><\/strong>Scalar or N-dimensional array which is the argument for the <em>Bessel\u2019s function<\/em><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Using Numpy i0 on N-Dimensional Arrays<\/h2>\n\n\n\n<p>Let us construct an array of dimensions 4&#215;1 and subject it to the Numpy <em>i0( ) <\/em>function to see what happens.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nar1 = np.array(&#x5B;-1, 0, -7, 9])\nnp.i0(ar1)\n<\/pre><\/div>\n\n\n<p>Following are the results for the above code.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"667\" height=\"91\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/Results-for-ar1-1.jpg\" alt=\"Results For Ar1 1 Numpy i0\" class=\"wp-image-40013\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/Results-for-ar1-1.jpg 667w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/Results-for-ar1-1-300x41.jpg 300w\" sizes=\"auto, (max-width: 667px) 100vw, 667px\" \/><figcaption class=\"wp-element-caption\">Results for &#8216;ar1&#8217;<\/figcaption><\/figure>\n\n\n\n<p>One can observe that the results are returned in an array of the same dimensions as that of the input array \u2018ar1\u2019. Each element in the output array is the result of the <em>Bessel\u2019s function <\/em>when its corresponding value from the input is being processed.<\/p>\n\n\n\n<p>The <em>i0( ) <\/em>function does not hold well when complex numbers are given as its inputs. The same is demonstrated below using an input array with complex numbers.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nar2= np.array(&#x5B;1.3, -2.5j])\nnp.i0(ar2)\n<\/pre><\/div>\n\n\n<p>The below error shall appear stating that the <em>i0( ) <\/em>function is not compatible with the complex numbers.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nTypeError: i0 not supported for complex values\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating plots for <em>numpy.i0( ) <\/em>results<\/strong><\/h2>\n\n\n\n<p>A mathematical function does not come a full circle till efforts are not taken to convert them into a plot. We shall do just that in this section. For this, we need to import the <em>pyplot<\/em> from the <em>matplotlib <\/em>library using the following code.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport matplotlib.pyplot as plt\n<\/pre><\/div>\n\n\n<p>Once done, let us use the results of the ar1 as the coordinates for the plot.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nar1 = np.array(&#x5B;-1, 0, 2, 5])\nr1 = np.i0(ar1)\n<\/pre><\/div>\n\n\n<p>Then the results shall be plotted against the x-axis in red using the below code.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nx = np.arange(0, 28, 7)\nplt.plot(x, r1, &#039;r&#039;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"523\" height=\"393\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/Plot-for-Bessels-function-Results-.jpg\" alt=\"Plot For Bessels Function Results  Numpy i0\" class=\"wp-image-40019\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/Plot-for-Bessels-function-Results-.jpg 523w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/01\/Plot-for-Bessels-function-Results--300x225.jpg 300w\" sizes=\"auto, (max-width: 523px) 100vw, 523px\" \/><figcaption class=\"wp-element-caption\">Plot for <em>Bessel&#8217;s function<\/em> Results <\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Now that we have reached the end of this article, hope it has elaborated on how to use the\u00a0<em>i0( )\u00a0<\/em>function from the\u00a0<em>numpy\u00a0<\/em>library. Here\u2019s another article that details the <a href=\"https:\/\/www.askpython.com\/python-modules\/numpy\/numpy-positive\" type=\"URL\" id=\"https:\/\/www.askpython.com\/python-modules\/how-to-use-numpy-positive-in-python\" target=\"_blank\" rel=\"noreferrer noopener\">usage of the<em> positive( ) <\/em>function from the\u00a0<em>numpy\u00a0<\/em>library<\/a> in Python. There are numerous other enjoyable and equally informative articles in <a href=\"https:\/\/www.askpython.com\/\" data-type=\"URL\" data-id=\"https:\/\/www.askpython.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">AskPython<\/a> that might be of great help to those who are looking to level up in Python.\u00a0<em>Audere est faucere<\/em>!<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.i0.html\" target=\"_blank\" rel=\"noopener\">Official documentation<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This article will talk about the Numpy i0 function. The year was 1817. It was a fine evening when a German astronomer by the name of Friedrich Wilhelm Bessel was taking a closer look at the movement of planets. Well, what else could he have referred to rather than the most advanced source available around [&hellip;]<\/p>\n","protected":false},"author":44,"featured_media":39886,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93],"tags":[],"class_list":["post-39862","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/39862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=39862"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/39862\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/39886"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=39862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=39862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=39862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}