{"id":37065,"date":"2022-11-30T07:04:41","date_gmt":"2022-11-30T07:04:41","guid":{"rendered":"https:\/\/www.askpython.com\/?p=37065"},"modified":"2023-01-29T09:27:33","modified_gmt":"2023-01-29T09:27:33","slug":"numpy-log10","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python-modules\/numpy\/numpy-log10","title":{"rendered":"Numpy log10 &#8211; Return the base 10 logarithm of the input array, element-wise."},"content":{"rendered":"\n<p>In this article, We will solve one straightforward problem &#8220;How to get the base 10 logarithm of an input array, element-wise&#8221;. We are going to obtain the logarithmic values of base 10 for elements comprised in an array. You can much better understand by analyzing the example below.<\/p>\n\n\n\n<p>Let us assume an array, input[2.35,\u00a00,\u00a00.36,\u00a01,\u00a05.69,\u00a01000,\u00a010] &#8211; We need to obtain corresponding logarithmic values for each element of this array in the form of a new array as [ 0.37106786 -inf -0.4436975 0. 0.75511227 3. 1. ]<code>. <\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>log<sub>10<\/sub>(2.35) = 0.37106786<\/li>\n\n\n\n<li>log<sub>10<\/sub>(0) = -inf<\/li>\n\n\n\n<li>log<sub>10<\/sub>(0.36) = -0.4436975<\/li>\n\n\n\n<li>log<sub>10<\/sub>(1) = 0.0<\/li>\n\n\n\n<li>log<sub>10<\/sub>(5.69) = 0.75511227<\/li>\n\n\n\n<li>log<sub>10<\/sub>(1000) = 3.0<\/li>\n\n\n\n<li>log<sub>10<\/sub>(10) = 1.0<\/li>\n<\/ul>\n\n\n\n<p>Before getting into our code snippet, Let us have quick look below!  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding Numpy Logarithmic Method<\/h2>\n\n\n\n<p>Python NumPy library provides some inbuilt methods for different mathematical operations. Among them,  <a href=\"https:\/\/www.askpython.com\/python-modules\/numpy\/python-numpy-log\" data-type=\"post\" data-id=\"5922\">Numpy.log()<\/a> is one of the most commonly used functions to perform logarithmic operations on an array. This method returns respective logarithmic values of<strong> <\/strong>base e = 2.71 for all elements in our input array<em>(as we are using the NumPy module)<\/em>. <\/p>\n\n\n\n<p>Numpy also provides individual methods to perform logarithmic base 10 (<code>NumPy.log10()<\/code>) and logarithmic base 2 (<code>NumPy.log2()<\/code>) operations<code>.<\/code> Today, We will learn how to implement the <code>Numpy.log10()<\/code> method in our code snippet today.<strong> <\/strong><\/p>\n\n\n\n<p>The Domain Numpy Logarithmic function lies in between the set of positive real numbers and The Range in the set of real numbers<strong>. Let us have a quick look below to understand the syntax for our function. <\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The syntax for Numpy.log10()<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#syntax for log base 10\nnumpy.log10(x, out=None, where=True, casting=&#039;same_kind&#039;, order=&#039;K&#039;, subok : &#x5B;bool, datatype])\n\n#syntax for log base2\nnumpy.log2(x, out=None, where=True, casting=&#039;same_kind&#039;, order=&#039;K&#039;, subok : &#x5B;bool, datatype])\n<\/pre><\/div>\n\n\n<p>The parameters used in the above snippet function as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>x:&nbsp;<\/strong>It can be a variable containing a value in Radian or it may be an array containing some value<\/li>\n\n\n\n<li><strong>out:<\/strong>&nbsp;A location in which the result is to be stored. If provided, it must have a shape similar to the input X. If not provided or None, a fresh value or result is returned. It\u2019s optional.<\/li>\n\n\n\n<li><strong>where = true:&nbsp;<\/strong>&nbsp;Where the condition is True, We must get our result or output for \u201cwhere = False\u201d We will not get any result. It\u2019s optional. y default its value is True.<\/li>\n\n\n\n<li><strong>casting=\u2019same_kind\u2019:<\/strong>&nbsp;It means only float64 to float32 value or results are allowed. The function shout cast values in this range or datatype.<\/li>\n\n\n\n<li><strong>order = \u2018K\u2019:<\/strong>&nbsp;It always results in an output array in the form of k ordered. (Note: There are 4 types of orders as&nbsp;<strong>{\u2018K\u2019, \u2018C\u2019, \u2018F\u2019, \u2018A\u2019}<\/strong>). It\u2019s optional.<\/li>\n\n\n\n<li><strong>subok<\/strong>: [bool, datatype]&nbsp;<strong>to make a subclass of the result or not<\/strong>. if True then provide a name for the subclass. It returns&nbsp;an array with the same shape and type as a given array. It\u2019s also optional.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Working with Numpy.log10() method<\/h2>\n\n\n\n<p>Now We will move into our code snippet sequentially that lets you explain How to implement our method. We are going with our google collab for our coding today. You guys must know that google collab provides the best platform to work on python as well. Without getting late. Let us get into it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Import Numpy<\/h3>\n\n\n\n<p>In this step, We will import the <code>Numpy<\/code> module to use <code>NumPy.log10()<\/code> function into our computer. We could not implement any NumPy methods without importing their dependency, the &#8220;Numpy Module&#8221;. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Step 2: Creating arrays to obtain Logarithmic values<\/h3>\n\n\n\n<p>In this step, we will create an array comprising values, for which the logarithmic values are to be obtained. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ny = numpy.array(&#x5B;2.35, 0, 0.36, 1, 5.69, 1000, 10])\n<\/pre><\/div>\n\n\n<p><strong>In case a user needs to input values into the array manually. He\/she can follow the below code snippet.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# creating  x array\nx = &#x5B;]\nn = int(input(&quot;Enter the number of values you want to enter : &quot;))\nfor i in range(0, n):\n    value = int(input())\n    x.append(value) \n<\/pre><\/div>\n\n\n<p>Executing the above code snippet will let a user enter the no. of values he wants to join. Moving Further, The user can enter individual values into the array as follows.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n Enter the number of values you want to enter : 3\n1\n2\n3\n&#x5B;1, 2, 3]\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Step 3: Implementing Numpy.log10() method<\/h3>\n\n\n\n<p>In this step, We will implement our function as below and pass both the arrays created in step 2.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\na = numpy.log10(y)\nb = numpy.log10(x)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Step 4: Getting output and Analyzing<\/h3>\n\n\n\n<p>In this final step, We will print our outputs loaded into variables a and b respectively.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nprint(a)\nprint(b)\n\n#output\n &#x5B; 0.37106786        -inf -0.4436975   0.          0.75511227  3.    1.        ]\n &#x5B;0.         0.30103    0.47712125]\n<\/pre><\/div>\n\n\n<p>You can see that The function returns an array comprising respective logarithmic values for all the elements in our input arrays. In this way, The <code>Numpy.log10()<\/code> method got successfully implemented. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Today, we learned how to use the numpy.log10() method to get the log of a value with the base 10. We tried two arrays as examples to help understand the concept better. If you&#8217;re interested in learning more about Numpy, don&#8217;t forget to check out our <a href=\"https:\/\/www.askpython.com\/python-modules\/numpy\">list of numpy tutorials<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, We will solve one straightforward problem &#8220;How to get the base 10 logarithm of an input array, element-wise&#8221;. We are going to obtain the logarithmic values of base 10 for elements comprised in an array. You can much better understand by analyzing the example below. Let us assume an array, input[2.35,\u00a00,\u00a00.36,\u00a01,\u00a05.69,\u00a01000,\u00a010] &#8211; [&hellip;]<\/p>\n","protected":false},"author":47,"featured_media":37069,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93],"tags":[],"class_list":["post-37065","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\/37065","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\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=37065"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/37065\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/37069"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=37065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=37065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=37065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}