{"id":3619,"date":"2020-07-17T22:15:34","date_gmt":"2020-07-17T16:45:34","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=3619"},"modified":"2026-07-13T12:27:25","modified_gmt":"2026-07-13T06:57:25","slug":"ln-in-python","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/ln-in-python\/","title":{"rendered":"ln in Python: math.log(), np.log(), Domain, and Precision"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> Use math.log(x) for the natural logarithm of a positive scalar, numpy.log(array) for element-wise array values, and math.log1p(x) when calculating log(1 + x) near zero. Validate the domain before calling the function.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-ln-domain-flow.png\" alt=\"Python natural logarithm diagram comparing math.log scalar, NumPy log arrays, positive-domain validation, log1p, and exp\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>Use math.log for scalars, np.log for arrays, and make the positive-domain policy explicit.<\/figcaption><\/figure>\n<p><code>ln in Python<\/code> means the natural logarithm, or log base <code>e<\/code>. Python does not have a separate <code>ln()<\/code> function in the standard library. The standard scalar function is <code>math.log(x)<\/code>, which returns the natural log when you pass one argument.<\/p>\n<p>Use natural logs when formulas involve continuous growth, decay, entropy, log likelihoods, or values measured on an exponential scale. The inverse operation is <code>math.exp(x)<\/code>, which raises <code>e<\/code> to a power. That pairing is the most important idea: <code>math.log()<\/code> moves from a positive value to its natural-log scale, and <code>math.exp()<\/code> moves back.<\/p>\n<p>The official <a href=\"https:\/\/docs.python.org\/3\/library\/math.html#math.log\">Python math.log documentation<\/a> covers the scalar function. For array-based numeric work, the <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.log.html\">NumPy log documentation<\/a> explains <code>numpy.log()<\/code>.<\/p>\n<p>Natural logs only accept positive real inputs in the standard <code>math<\/code> module. If the input is zero or negative, Python raises <code>ValueError<\/code>. Validate data before logging it, especially when values come from files, forms, sensors, or calculations that can produce zero.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 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\/ln-in-python\/#Calculate_ln_With_mathlog\" >Calculate ln With math.log()<\/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\/ln-in-python\/#Log_Several_Positive_Numbers\" >Log Several Positive Numbers<\/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\/ln-in-python\/#Handle_Domain_Errors\" >Handle Domain Errors<\/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\/ln-in-python\/#Convert_Natural_Logs_To_Another_Base\" >Convert Natural Logs To Another Base<\/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\/ln-in-python\/#Reverse_ln_With_exp\" >Reverse ln With exp()<\/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\/ln-in-python\/#Use_Decimal_For_More_Precision\" >Use Decimal For More Precision<\/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\/ln-in-python\/#Common_ln_Mistakes\" >Common ln Mistakes<\/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\/ln-in-python\/#Choose_Scalar_Or_Array_Math\" >Choose Scalar Or Array Math<\/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\/ln-in-python\/#Handle_The_Positive_Domain\" >Handle The Positive Domain<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/ln-in-python\/#Use_Stable_Forms_Near_Zero\" >Use Stable Forms Near Zero<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/ln-in-python\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/ln-in-python\/#How_do_I_calculate_ln_in_Python\" >How do I calculate ln in Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/ln-in-python\/#How_do_I_calculate_natural_logs_for_a_NumPy_array\" >How do I calculate natural logs for a NumPy array?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/ln-in-python\/#Why_does_mathlog_raise_a_ValueError\" >Why does math.log() raise a ValueError?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/ln-in-python\/#When_should_I_use_mathlog1p\" >When should I use math.log1p()?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Calculate_ln_With_mathlog\"><\/span>Calculate ln With math.log()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Import the <code>math<\/code> module and call <code>math.log()<\/code> with one positive number. Passing <code>math.e<\/code> returns <code>1<\/code>, because the natural log of <code>e<\/code> is one.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import math\n\nvalue = math.e\nnatural_log = math.log(value)\n\nprint(natural_log)\nprint(math.isclose(natural_log, 1.0))\n<\/code><\/pre>\n<\/div>\n<p>This is the direct replacement for <code>ln(x)<\/code> notation from math classes and calculators. The function name is <code>log<\/code>, but one argument means natural log, not base ten.<\/p>\n<p>Keep the <code>math.<\/code> prefix in examples and application code unless there is a strong local convention to import functions directly. The prefix makes the source of the function clear and avoids confusion with other libraries that may also define a log function.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Log_Several_Positive_Numbers\"><\/span>Log Several Positive Numbers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A simple loop is enough when you have a short list of scalar values. Each input must be positive before it reaches <code>math.log()<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import math\n\nnumbers = [1, math.e, math.e ** 2, 10]\n\nfor number in numbers:\n    print(number, math.log(number))\n<\/code><\/pre>\n<\/div>\n<p>The output shows useful anchor points. The natural log of <code>1<\/code> is <code>0<\/code>, the natural log of <code>e<\/code> is <code>1<\/code>, and the natural log of <code>e ** 2<\/code> is <code>2<\/code>.<\/p>\n<p>For large arrays, use NumPy instead of a Python loop. For a small report, command-line check, or validation step, the standard-library loop is often clearer and keeps dependencies out of the script.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/natural-log-log-b147.png\" alt=\"Python Pool infographic showing a positive input, natural log, Euler number, and output value\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Natural logarithm: A positive input, natural log, Euler number, and output value.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Handle_Domain_Errors\"><\/span>Handle Domain Errors<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The natural log is defined for positive real numbers. Guard that rule explicitly when bad input should produce a readable error instead of a traceback from deep inside a calculation.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import math\n\ndef natural_log(number):\n    if number &lt;= 0:\n        raise ValueError(\"natural log input must be positive\")\n    return math.log(number)\n\nfor number in [1.0, 2.5, 0.0]:\n    try:\n        print(number, natural_log(number))\n    except ValueError as error:\n        print(number, error)\n<\/code><\/pre>\n<\/div>\n<p>This pattern is useful in functions that receive user input or data from another system. The check states the rule near the boundary of the function, so later code can assume the value is safe to log.<\/p>\n<p>Do not silently replace zero with a tiny number unless that is a documented statistical choice. A hidden adjustment can change results in ways that are hard to audit later.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Convert_Natural_Logs_To_Another_Base\"><\/span>Convert Natural Logs To Another Base<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Natural logs can convert to any other base by dividing by the natural log of that base. Python also supports <code>math.log(x, base)<\/code>, but the conversion formula is useful when a derivation is written in terms of <code>ln<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import math\n\nnumber = 1000\nbase = 10\n\nconverted = math.log(number) \/ math.log(base)\ndirect = math.log(number, base)\n\nprint(converted)\nprint(direct)\n<\/code><\/pre>\n<\/div>\n<p>Both lines return the same base-ten log at normal floating-point precision. Use the two-argument form when it reads better. Use the division formula when you want the natural-log relationship to stay visible in the code.<\/p>\n<p>The same approach works for base two, base ten, or any positive base other than one. Validate the base when it comes from input, because base zero, base one, and negative bases are not valid for real logarithms.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/natural-log-api-b147.png\" alt=\"Python Pool infographic comparing math.log, NumPy log, scalar values, arrays, and dtype\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Python APIs: Math.log, NumPy log, scalar values, arrays, and dtype.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Reverse_ln_With_exp\"><\/span>Reverse ln With exp()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The inverse of <code>math.log(x)<\/code> is <code>math.exp(x)<\/code>. If you log a positive value and then apply <code>exp()<\/code>, you should get the original value back within floating-point tolerance.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import math\n\nstarting_value = 7.5\nlogged = math.log(starting_value)\nrestored = math.exp(logged)\n\nprint(logged)\nprint(restored)\nprint(math.isclose(restored, starting_value))\n<\/code><\/pre>\n<\/div>\n<p>This relationship helps when checking formulas. For example, many models store or optimize values on a log scale, then convert back to the original scale for display or interpretation.<\/p>\n<p>Use <code>math.isclose()<\/code> for the comparison because floating-point arithmetic can introduce tiny rounding differences. Exact equality is not the right test for most decimal-looking numeric results.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_Decimal_For_More_Precision\"><\/span>Use Decimal For More Precision<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For ordinary numeric scripts, <code>math.log()<\/code> and floats are the right default. If you need configurable decimal precision, the standard <code>decimal<\/code> module provides a natural-log method on <code>Decimal<\/code> numbers.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from decimal import Decimal, getcontext\n\ngetcontext().prec = 40\nnumber = Decimal(\"2.7182818284590452353602874713527\")\nlogged = number.ln()\n\nprint(logged)\n<\/code><\/pre>\n<\/div>\n<p>This is slower than float math, but it gives you control over decimal precision for specialized calculations, financial-style rounding rules, or educational examples that need more printed digits.<\/p>\n<p>Most code should still start with <code>math.log()<\/code>. Move to <code>Decimal<\/code> only when the precision requirement is real and tested, not just because more digits look more exact.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/natural-log-domain-b147.png\" alt=\"Python Pool infographic showing zero, negative input, complex values, domain errors, and validation\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Domain rules: Zero, negative input, complex values, domain errors, and validation.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Common_ln_Mistakes\"><\/span>Common ln Mistakes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first mistake is looking for <code>math.ln()<\/code>. Python uses <code>math.log(x)<\/code> for natural logs and <code>math.log(x, base)<\/code> when you need another base.<\/p>\n<p>The second mistake is passing zero or a negative number to the scalar <code>math<\/code> function. Check the domain first and decide whether invalid input should be rejected, filtered, or handled in a complex-number workflow.<\/p>\n<p>The third mistake is mixing scalar and array APIs. Use <code>math.log()<\/code> for one Python number. Use NumPy&#8217;s log function for arrays and vectorized calculations.<\/p>\n<p>The practical rule is simple: write <code>math.log(x)<\/code> for <code>ln(x)<\/code>, keep inputs positive, use <code>math.exp()<\/code> to reverse the transform, and choose a different base only when the problem actually asks for it.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Choose_Scalar_Or_Array_Math\"><\/span>Choose Scalar Or Array Math<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>math.log(x)<\/code> is the standard-library scalar operation for ln. A one-argument call uses base <code>e<\/code>; a second argument can request another base. For arrays, <code>numpy.log()<\/code> applies the natural logarithm element by element and follows NumPy&#8217;s rules for invalid real-domain values.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import math\nimport numpy as np\n\nscalar = math.log(math.e)\nvalues = np.array([1.0, math.e, math.e ** 2])\narray_logs = np.log(values)\nprint(scalar, array_logs)<\/code><\/pre>\n<\/div>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/natural-log-check-b147.png\" alt=\"Python Pool infographic testing small values, large values, round trips, precision, and output\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Precision checks: Small values, large values, round trips, precision, and output.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Handle_The_Positive_Domain\"><\/span>Handle The Positive Domain<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Real natural logarithms are defined for positive inputs. Zero and negative values usually indicate a data or modeling decision that must be handled before the call. You can filter invalid observations, reject the record, use a complex-number model, or apply a domain-specific transform, but do not silently turn an invalid value into a meaningful result.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_Stable_Forms_Near_Zero\"><\/span>Use Stable Forms Near Zero<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When the expression is <code>log(1 + x)<\/code> and <code>x<\/code> is very small, <code>math.log1p(x)<\/code> is designed to retain more precision than calculating <code>math.log(1 + x)<\/code> directly. The inverse of a natural log is <code>math.exp()<\/code>; use that pair when checking a transformation or round trip.<\/p>\n<p data-pythonpool-link-set=\"2026-07-13-final\">For mathematical transformations, compare natural logarithms with absolute values and powers. Read <a href=\"https:\/\/www.pythonpool.com\/python-absolute-value\/\">python absolute value<\/a> and <a href=\"https:\/\/www.pythonpool.com\/numpy-power\/\">numpy power<\/a> for the related workflow.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_calculate_ln_in_Python\"><\/span>How do I calculate ln in Python?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Call math.log(x) with one positive real argument; a one-argument math.log call calculates the natural logarithm with base e.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_calculate_natural_logs_for_a_NumPy_array\"><\/span>How do I calculate natural logs for a NumPy array?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use numpy.log(array) for element-wise natural logarithms and define how invalid or non-positive values should be handled.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_does_mathlog_raise_a_ValueError\"><\/span>Why does math.log() raise a ValueError?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Real natural logarithms require positive inputs, so zero or negative values violate the real-valued domain.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"When_should_I_use_mathlog1p\"><\/span>When should I use math.log1p()?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use math.log1p(x) for log(1 + x) when x is close to zero and preserving numerical precision matters.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"How do I calculate ln in Python?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Call math.log(x) with one positive real argument; a one-argument math.log call calculates the natural logarithm with base e.\"}},{\"@type\":\"Question\",\"name\":\"How do I calculate natural logs for a NumPy array?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use numpy.log(array) for element-wise natural logarithms and define how invalid or non-positive values should be handled.\"}},{\"@type\":\"Question\",\"name\":\"Why does math.log() raise a ValueError?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Real natural logarithms require positive inputs, so zero or negative values violate the real-valued domain.\"}},{\"@type\":\"Question\",\"name\":\"When should I use math.log1p()?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use math.log1p(x) for log(1 + x) when x is close to zero and preserving numerical precision matters.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calculate ln in Python with math.log() for scalars, np.log() for arrays, explicit positive-domain validation, and stable near-zero formulas.<\/p>\n","protected":false},"author":3,"featured_media":34176,"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":[15],"tags":[1571,1581,1570,1574,1584,1583,1580,1582,1568,1566,1576,1579,1578,1577,1569,1567,1575,1572,1573],"class_list":["post-3619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-drop-ln-in-string-python","tag-how-to-compute-ln-in-python","tag-how-to-do-ln-in-python","tag-how-to-graph-ln-in-python","tag-how-to-put-ln-function-in-python","tag-how-to-take-the-ln-of-a-in-python","tag-how-to-use-ln-function-in-python","tag-how-to-use-ln-in-python","tag-ln-for-a-matrix-in-python","tag-ln-function-in-python","tag-ln-in-python","tag-ln-in-python-math","tag-ln-in-python-2","tag-ln-in-python-length","tag-logaritmo-ln-in-python","tag-python-why-does-my-ln-have-a-in-it","tag-use-ln-in-python","tag-usig-ln-in-python","tag-what-dose-the-ln-and-col-mean-in-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>ln in Python: math.log(), np.log(), Domain, and Precision<\/title>\n<meta name=\"description\" content=\"Calculate natural logs in Python with math.log(), NumPy log(), log1p(), base conversion, positive-domain checks, and exp() round trips.\" \/>\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\/ln-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ln in Python: math.log(), np.log(), Domain, and Precision\" \/>\n<meta property=\"og:description\" content=\"Calculate ln in Python with math.log() for scalars, np.log() for arrays, explicit positive-domain validation, and stable near-zero formulas.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/ln-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-17T16:45:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T06:57:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-ln-domain-flow.png\" \/>\n<meta name=\"author\" content=\"Ashwini Mandani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-ln-domain-flow.png\" \/>\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=\"Ashwini Mandani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/\"},\"author\":{\"name\":\"Ashwini Mandani\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/8a75fb48eb1f3dc952df65a8c28ac056\"},\"headline\":\"ln in Python: math.log(), np.log(), Domain, and Precision\",\"datePublished\":\"2020-07-17T16:45:34+00:00\",\"dateModified\":\"2026-07-13T06:57:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/\"},\"wordCount\":1166,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/ln-in-python-guide-pythonpool.png\",\"keywords\":[\"drop ln in string python\",\"how to compute ln in python\",\"how to do ln in python\",\"how to graph ln in python\",\"how to put ln function in python\",\"how to take the ln of a in python\",\"how to use ln function in python\",\"how to use ln in python\",\"ln for a matrix in python\",\"ln function in python\",\"ln in python\",\"ln in python math\",\"ln() in python\",\"ln() in python length\",\"logaritmo ln in python\",\"python why does my ln have a * in it\",\"use ln in python\",\"usig ln in python\",\"what dose the ln and col mean in python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/\",\"name\":\"ln in Python: math.log(), np.log(), Domain, and Precision\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/ln-in-python-guide-pythonpool.png\",\"datePublished\":\"2020-07-17T16:45:34+00:00\",\"dateModified\":\"2026-07-13T06:57:25+00:00\",\"description\":\"Calculate natural logs in Python with math.log(), NumPy log(), log1p(), base conversion, positive-domain checks, and exp() round trips.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/ln-in-python-guide-pythonpool.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/ln-in-python-guide-pythonpool.png\",\"width\":1350,\"height\":650,\"caption\":\"ln in Python natural log guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/ln-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ln in Python: math.log(), np.log(), Domain, and Precision\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"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\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/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\\\/8a75fb48eb1f3dc952df65a8c28ac056\",\"name\":\"Ashwini Mandani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"caption\":\"Ashwini Mandani\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"ln in Python: math.log(), np.log(), Domain, and Precision","description":"Calculate natural logs in Python with math.log(), NumPy log(), log1p(), base conversion, positive-domain checks, and exp() round trips.","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\/ln-in-python\/","og_locale":"en_US","og_type":"article","og_title":"ln in Python: math.log(), np.log(), Domain, and Precision","og_description":"Calculate ln in Python with math.log() for scalars, np.log() for arrays, explicit positive-domain validation, and stable near-zero formulas.","og_url":"https:\/\/www.pythonpool.com\/ln-in-python\/","og_site_name":"Python Pool","article_published_time":"2020-07-17T16:45:34+00:00","article_modified_time":"2026-07-13T06:57:25+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-ln-domain-flow.png","type":"","width":"","height":""}],"author":"Ashwini Mandani","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-ln-domain-flow.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Ashwini Mandani","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/ln-in-python\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/ln-in-python\/"},"author":{"name":"Ashwini Mandani","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056"},"headline":"ln in Python: math.log(), np.log(), Domain, and Precision","datePublished":"2020-07-17T16:45:34+00:00","dateModified":"2026-07-13T06:57:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/ln-in-python\/"},"wordCount":1166,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/ln-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/ln-in-python-guide-pythonpool.png","keywords":["drop ln in string python","how to compute ln in python","how to do ln in python","how to graph ln in python","how to put ln function in python","how to take the ln of a in python","how to use ln function in python","how to use ln in python","ln for a matrix in python","ln function in python","ln in python","ln in python math","ln() in python","ln() in python length","logaritmo ln in python","python why does my ln have a * in it","use ln in python","usig ln in python","what dose the ln and col mean in python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/ln-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/ln-in-python\/","url":"https:\/\/www.pythonpool.com\/ln-in-python\/","name":"ln in Python: math.log(), np.log(), Domain, and Precision","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/ln-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/ln-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/ln-in-python-guide-pythonpool.png","datePublished":"2020-07-17T16:45:34+00:00","dateModified":"2026-07-13T06:57:25+00:00","description":"Calculate natural logs in Python with math.log(), NumPy log(), log1p(), base conversion, positive-domain checks, and exp() round trips.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/ln-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/ln-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/ln-in-python\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/ln-in-python-guide-pythonpool.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/ln-in-python-guide-pythonpool.png","width":1350,"height":650,"caption":"ln in Python natural log guide"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/ln-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"ln in Python: math.log(), np.log(), Domain, and Precision"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","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":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/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\/8a75fb48eb1f3dc952df65a8c28ac056","name":"Ashwini Mandani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","caption":"Ashwini Mandani"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3619","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=3619"}],"version-history":[{"count":14,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3619\/revisions"}],"predecessor-version":[{"id":41391,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3619\/revisions\/41391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/34176"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=3619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=3619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=3619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}