{"id":997828,"date":"2024-12-27T09:27:28","date_gmt":"2024-12-27T01:27:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/997828.html"},"modified":"2024-12-27T09:27:31","modified_gmt":"2024-12-27T01:27:31","slug":"python%e5%a6%82%e4%bd%95%e8%a1%a8%e7%a4%baln%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/997828.html","title":{"rendered":"python\u5982\u4f55\u8868\u793aln\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073456\/3deb793e-52a8-4d35-b803-d47990039f24.webp\" alt=\"python\u5982\u4f55\u8868\u793aln\u51fd\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8868\u793a\u81ea\u7136\u5bf9\u6570\u51fd\u6570\uff08ln\uff09\u7684\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528<code>math<\/code>\u5e93\u4e2d\u7684<code>log<\/code>\u51fd\u6570\u3001<code>numpy<\/code>\u5e93\u4e2d\u7684<code>log<\/code>\u51fd\u6570\u3001\u4ee5\u53ca<code>sympy<\/code>\u5e93\u4e2d\u7684<code>ln<\/code>\u51fd\u6570\u3002<\/strong>\u5176\u4e2d\uff0c\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528<code>math.log<\/code>\u51fd\u6570\uff0c\u56e0\u4e3a\u5b83\u662f\u5185\u7f6e\u5728Python\u6807\u51c6\u5e93\u4e2d\u7684\uff0c\u4f7f\u7528\u65b9\u4fbf\u4e14\u6027\u80fd\u8f83\u597d\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\uff0c\u5373<code>math.log<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u8981\u5728Python\u4e2d\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165<code>math<\/code>\u5e93\u3002\u7136\u540e\uff0c\u4f7f\u7528<code>math.log(x)<\/code>\u6765\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff0c\u5176\u4e2d<code>x<\/code>\u662f\u9700\u8981\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u7684\u6570\u5b57\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e2a\u51fd\u6570\u9ed8\u8ba4\u662f\u4ee5\u81ea\u7136\u5bf9\u6570\u7684\u5e95\u6570<code>e<\/code>\u4e3a\u57fa\u6570\u8fdb\u884c\u8ba1\u7b97\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4<code>math.log(x)<\/code>\u7b49\u4ef7\u4e8e\u6570\u5b66\u4e2d\u7684<code>ln(x)<\/code>\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<code>ln(10)<\/code>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>result = math.log(10)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5f97\u5230<code>ln(10)<\/code>\u7684\u503c\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u5982\u679c\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u5e93\u6765\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff0c\u4f8b\u5982<code>numpy<\/code>\u6216<code>sympy<\/code>\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u76f8\u5e94\u7684\u65b9\u6cd5\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001PYTHON\u4e2d\u4f7f\u7528MATH\u5e93\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/p>\n<\/p>\n<p><p><code>math<\/code>\u5e93\u662fPython\u4e2d\u4e00\u4e2a\u57fa\u7840\u800c\u5f3a\u5927\u7684\u6570\u5b66\u8fd0\u7b97\u5e93\uff0c\u5176\u4e2d\u7684<code>log<\/code>\u51fd\u6570\u53ef\u4ee5\u7528\u4e8e\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u3002<code>math.log(x)<\/code>\u51fd\u6570\u9ed8\u8ba4\u4ee5<code>e<\/code>\u4e3a\u5e95\uff0c\u8ba1\u7b97<code>x<\/code>\u7684\u81ea\u7136\u5bf9\u6570\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5bfc\u5165\u548c\u4f7f\u7528<code>math.log<\/code><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5bfc\u5165<code>math<\/code>\u5e93\u624d\u80fd\u4f7f\u7528\u5176\u4e2d\u7684<code>log<\/code>\u51fd\u6570\u3002\u5bfc\u5165\u5e93\u540e\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>math.log<\/code>\u6765\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/strong><\/h2>\n<p>value = 10<\/p>\n<p>ln_value = math.log(value)<\/p>\n<p>print(f&quot;The natural log of {value} is {ln_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528<code>math.log<\/code>\u8ba1\u7b97\u5176\u4ed6\u5e95\u6570\u7684\u5bf9\u6570<\/li>\n<\/ol>\n<p><p>\u867d\u7136<code>math.log<\/code>\u9ed8\u8ba4\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff0c\u4f46\u5b83\u4e5f\u5141\u8bb8\u901a\u8fc7\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\u5176\u4ed6\u5e95\u6570\u3002\u5982\u679c\u5e0c\u671b\u8ba1\u7b97\u4ee5\u67d0\u4e2a\u7279\u5b9a\u5e95\u6570\u7684\u5bf9\u6570\uff0c\u53ef\u4ee5\u4f20\u9012\u7b2c\u4e8c\u4e2a\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u4ee510\u4e3a\u5e95\u7684\u5bf9\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>value = 100<\/p>\n<p>log_base_10 = math.log(value, 10)<\/p>\n<p>print(f&quot;The log base 10 of {value} is {log_base_10}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<code>math.log<\/code>\u51fd\u6570\u5728\u5904\u7406\u8d1f\u6570\u548c\u96f6\u65f6\u4f1a\u629b\u51fa<code>ValueError<\/code>\uff0c\u56e0\u4e3a\u5bf9\u6570\u51fd\u6570\u5728\u8fd9\u4e9b\u503c\u4e0a\u662f\u672a\u5b9a\u4e49\u7684\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001PYTHON\u4e2d\u4f7f\u7528NUMPY\u5e93\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/p>\n<\/p>\n<p><p><code>numpy<\/code>\u5e93\u662fPython\u4e2d\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u5176\u4e2d\u4e5f\u63d0\u4f9b\u4e86<code>log<\/code>\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u3002<code>numpy<\/code>\u7684<code>log<\/code>\u51fd\u6570\u4e0d\u4ec5\u652f\u6301\u6807\u91cf\u8fd0\u7b97\uff0c\u8fd8\u652f\u6301\u6570\u7ec4\u8fd0\u7b97\uff0c\u975e\u5e38\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528<code>numpy.log<\/code>\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/li>\n<\/ol>\n<p><p><code>numpy.log<\/code>\u51fd\u6570\u4e0e<code>math.log<\/code>\u51fd\u6570\u7c7b\u4f3c\uff0c\u4f46\u5b83\u53ef\u4ee5\u76f4\u63a5\u5e94\u7528\u4e8e\u6570\u7ec4\uff0c\u4f7f\u5176\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/strong><\/h2>\n<p>values = np.array([1, 10, 100])<\/p>\n<p>ln_values = np.log(values)<\/p>\n<p>print(f&quot;The natural logs are {ln_values}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><code>numpy.log<\/code>\u7684\u6570\u7ec4\u5904\u7406\u80fd\u529b<\/li>\n<\/ol>\n<p><p><code>numpy.log<\/code>\u51fd\u6570\u4e0d\u4ec5\u53ef\u4ee5\u5904\u7406\u5355\u4e2a\u6570\u503c\uff0c\u8fd8\u53ef\u4ee5\u5904\u7406\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u3002\u5b83\u5728\u5904\u7406\u6570\u636e\u96c6\u3001\u4fe1\u53f7\u5904\u7406\u7b49\u9886\u57df\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<\/strong><\/h2>\n<p>values = np.array([1, np.e, np.e&lt;strong&gt;2, np.e&lt;\/strong&gt;3])<\/p>\n<h2><strong>\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u81ea\u7136\u5bf9\u6570<\/strong><\/h2>\n<p>ln_values = np.log(values)<\/p>\n<p>print(f&quot;The natural logs of the array are {ln_values}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u4e0e<code>math.log<\/code>\u7c7b\u4f3c\uff0c<code>numpy.log<\/code>\u5728\u5904\u7406\u8d1f\u6570\u548c\u96f6\u65f6\u4e5f\u4f1a\u8fd4\u56de<code>NaN<\/code>\u6216<code>-inf<\/code>\uff0c\u6839\u636e\u8f93\u5165\u7684\u5177\u4f53\u503c\u548c\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001PYTHON\u4e2d\u4f7f\u7528SYMPY\u5e93\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/p>\n<\/p>\n<p><p><code>sympy<\/code>\u662f\u4e00\u4e2a\u7528\u4e8e\u7b26\u53f7\u6570\u5b66\u8ba1\u7b97\u7684Python\u5e93\uff0c\u5b83\u5141\u8bb8\u5bf9\u6570\u5b66\u8868\u8fbe\u5f0f\u8fdb\u884c\u7b26\u53f7\u5316\u64cd\u4f5c\u3002<code>sympy<\/code>\u4e2d\u7684<code>ln<\/code>\u51fd\u6570\u53ef\u4ee5\u7528\u4e8e\u8ba1\u7b97\u7b26\u53f7\u81ea\u7136\u5bf9\u6570\uff0c\u975e\u5e38\u9002\u5408\u9700\u8981\u7cbe\u786e\u89e3\u6790\u89e3\u6216\u7b26\u53f7\u5316\u8868\u8fbe\u5f0f\u7684\u573a\u5408\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528<code>sympy.ln<\/code>\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/li>\n<\/ol>\n<p><p><code>sympy.ln<\/code>\u51fd\u6570\u53ef\u4ee5\u8fdb\u884c\u7b26\u53f7\u8ba1\u7b97\uff0c\u8fd4\u56de\u81ea\u7136\u5bf9\u6570\u7684\u7b26\u53f7\u5316\u7ed3\u679c\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u6570\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sympy import ln, symbols<\/p>\n<h2><strong>\u5b9a\u4e49\u7b26\u53f7<\/strong><\/h2>\n<p>x = symbols(&#39;x&#39;)<\/p>\n<h2><strong>\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u7684\u7b26\u53f7\u8868\u8fbe\u5f0f<\/strong><\/h2>\n<p>ln_expr = ln(x)<\/p>\n<p>print(f&quot;The symbolic natural log expression is {ln_expr}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u67d0\u4e2a\u5177\u4f53\u503c\u7684\u81ea\u7136\u5bf9\u6570<\/strong><\/h2>\n<p>ln_value = ln_expr.subs(x, 10)<\/p>\n<p>print(f&quot;The natural log of 10 is {ln_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><code>sympy.ln<\/code>\u7684\u7b26\u53f7\u5316\u80fd\u529b<\/li>\n<\/ol>\n<p><p><code>sympy<\/code>\u7684\u7b26\u53f7\u5316\u80fd\u529b\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u8fdb\u884c\u4ee3\u6570\u5316\u7b80\u3001\u6c42\u5bfc\u3001\u79ef\u5206\u7b49\u64cd\u4f5c\uff0c\u662f\u6570\u5b66\u7814\u7a76\u548c\u5de5\u7a0b\u8ba1\u7b97\u4e2d\u5e38\u7528\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sympy import ln, diff, integrate, symbols<\/p>\n<h2><strong>\u5b9a\u4e49\u7b26\u53f7<\/strong><\/h2>\n<p>x = symbols(&#39;x&#39;)<\/p>\n<h2><strong>\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u7684\u5bfc\u6570<\/strong><\/h2>\n<p>ln_derivative = diff(ln(x), x)<\/p>\n<p>print(f&quot;The derivative of ln(x) is {ln_derivative}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u7684\u79ef\u5206<\/strong><\/h2>\n<p>ln_integral = integrate(ln(x), x)<\/p>\n<p>print(f&quot;The integral of ln(x) is {ln_integral}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<code>sympy<\/code>\u5e93\u9002\u5408\u9700\u8981\u7b26\u53f7\u8ba1\u7b97\u7684\u573a\u5408\uff0c\u5982\u679c\u4ec5\u4ec5\u9700\u8981\u6570\u503c\u8ba1\u7b97\uff0c<code>math<\/code>\u6216<code>numpy<\/code>\u53ef\u80fd\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001PYTHON\u4e2d\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u7684\u5b9e\u9645\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u79d1\u5b66\u3001\u91d1\u878d\u5206\u6790\u3001\u7269\u7406\u6a21\u62df\u7b49\u9886\u57df\uff0c\u81ea\u7136\u5bf9\u6570\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u8ba1\u7b97\u4e2d\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u5c55\u793a\u51e0\u4e2a\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6307\u6570\u589e\u957f\u548c\u8870\u51cf\u6a21\u578b<\/li>\n<\/ol>\n<p><p>\u81ea\u7136\u5bf9\u6570\u5728\u63cf\u8ff0\u6307\u6570\u589e\u957f\u548c\u8870\u51cf\u8fc7\u7a0b\u4e2d\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff0c\u5728\u91d1\u878d\u9886\u57df\u4e2d\uff0c\u81ea\u7136\u5bf9\u6570\u7528\u4e8e\u8ba1\u7b97\u590d\u5229\u548c\u6536\u76ca\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u590d\u5229\u8ba1\u7b97<\/strong><\/h2>\n<p>P = 1000  # \u521d\u59cb\u672c\u91d1<\/p>\n<p>r = 0.05  # \u5e74\u5229\u7387<\/p>\n<p>t = 10    # \u5e74\u9650<\/p>\n<h2><strong>\u8ba1\u7b97\u672a\u6765\u503c<\/strong><\/h2>\n<p>A = P * math.exp(r * t)<\/p>\n<p>print(f&quot;The future value of the investment is {A}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4fe1\u606f\u8bba\u4e2d\u7684\u71b5\u8ba1\u7b97<\/li>\n<\/ol>\n<p><p>\u5728\u4fe1\u606f\u8bba\u4e2d\uff0c\u71b5\u662f\u8861\u91cf\u4fe1\u606f\u4e0d\u786e\u5b9a\u6027\u7684\u4e00\u4e2a\u91cd\u8981\u6307\u6807\uff0c\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u5e38\u5e38\u4f7f\u7528\u81ea\u7136\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u6982\u7387\u5206\u5e03<\/strong><\/h2>\n<p>probabilities = np.array([0.2, 0.5, 0.3])<\/p>\n<h2><strong>\u8ba1\u7b97\u71b5<\/strong><\/h2>\n<p>entropy = -np.sum(probabilities * np.log(probabilities))<\/p>\n<p>print(f&quot;The entropy of the distribution is {entropy}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4e2d\u7684\u635f\u5931\u51fd\u6570<\/li>\n<\/ol>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u4ea4\u53c9\u71b5\u635f\u5931\u51fd\u6570\u7528\u4e8e\u5206\u7c7b\u95ee\u9898\uff0c\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u81ea\u7136\u5bf9\u6570\u662f\u4e00\u4e2a\u6838\u5fc3\u90e8\u5206\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u771f\u5b9e\u6807\u7b7e\u548c\u9884\u6d4b\u6982\u7387<\/strong><\/h2>\n<p>y_true = np.array([1, 0, 1])<\/p>\n<p>y_pred = np.array([0.8, 0.1, 0.6])<\/p>\n<h2><strong>\u8ba1\u7b97\u4ea4\u53c9\u71b5\u635f\u5931<\/strong><\/h2>\n<p>cross_entropy_loss = -np.sum(y_true * np.log(y_pred) + (1 - y_true) * np.log(1 - y_pred))<\/p>\n<p>print(f&quot;The cross-entropy loss is {cross_entropy_loss}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u7684\u65b9\u5f0f\uff0c\u5305\u62ec<code>math<\/code>\u5e93\u3001<code>numpy<\/code>\u5e93\u548c<code>sympy<\/code>\u5e93\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u7684\u4e0d\u540c\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0d\u540c\u7684\u65b9\u6cd5\u8fdb\u884c\u8ba1\u7b97\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong><code>math.log<\/code><\/strong>\uff1a\u9002\u7528\u4e8e\u6570\u503c\u8ba1\u7b97\uff0c\u6027\u80fd\u8f83\u597d\uff0c\u9002\u5408\u4e00\u822c\u6027\u6570\u503c\u8fd0\u7b97\u3002<\/li>\n<li><strong><code>numpy.log<\/code><\/strong>\uff1a\u9002\u7528\u4e8e\u6570\u7ec4\u8fd0\u7b97\uff0c\u80fd\u591f\u9ad8\u6548\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\uff0c\u9002\u5408\u79d1\u5b66\u8ba1\u7b97\u3002<\/li>\n<li><strong><code>sympy.ln<\/code><\/strong>\uff1a\u9002\u7528\u4e8e\u7b26\u53f7\u8ba1\u7b97\uff0c\u80fd\u591f\u8fdb\u884c\u89e3\u6790\u89e3\u7684\u8ba1\u7b97\u548c\u8868\u8fbe\u5f0f\u7b80\u5316\uff0c\u9002\u5408\u6570\u5b66\u7814\u7a76\u3002<\/li>\n<\/ul>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u81ea\u7136\u5bf9\u6570\u5e7f\u6cdb\u7528\u4e8e\u91d1\u878d\u5206\u6790\u3001\u4fe1\u606f\u8bba\u548c\u673a\u5668\u5b66\u4e60\u7b49\u9886\u57df\u3002\u6839\u636e\u573a\u666f\u548c\u9700\u6c42\u7684\u4e0d\u540c\uff0c\u53ef\u4ee5\u9009\u62e9\u5408\u9002\u7684\u5e93\u548c\u65b9\u6cd5\u6765\u8fdb\u884c\u8ba1\u7b97\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u60a8\u80fd\u591f\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728Python\u4e2d\u8868\u793a\u548c\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff0c\u4ee5\u53ca\u5176\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u91cd\u8981\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff08\u5373\u4ee5e\u4e3a\u5e95\u7684\u5bf9\u6570\uff09\u53ef\u4ee5\u4f7f\u7528<code>math<\/code>\u6a21\u5757\u4e2d\u7684<code>log<\/code>\u51fd\u6570\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u4f7f\u7528<code>math.log(x)<\/code>\u53ef\u4ee5\u5f97\u5230x\u7684\u81ea\u7136\u5bf9\u6570\u503c\u3002\u5982\u679c\u4f60\u6ca1\u6709\u5b89\u88c5<code>math<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528Python\u81ea\u5e26\u7684\u6807\u51c6\u5e93\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u7528\u4e8e\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\uff1f<\/strong><br \/>\u9664\u4e86<code>math<\/code>\u6a21\u5757\u5916\uff0c<code>numpy<\/code>\u5e93\u4e5f\u53ef\u4ee5\u8fdb\u884c\u81ea\u7136\u5bf9\u6570\u7684\u8ba1\u7b97\u3002\u901a\u8fc7<code>numpy.log(x)<\/code>\uff0c\u4f60\u53ef\u4ee5\u8ba1\u7b97\u6570\u7ec4\u6216\u6570\u503c\u7684\u81ea\u7136\u5bf9\u6570\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u7684\u6570\u636e\u8ba1\u7b97\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u8d1f\u6570\u6216\u96f6\u7684\u81ea\u7136\u5bf9\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5c1d\u8bd5\u8ba1\u7b97\u8d1f\u6570\u6216\u96f6\u7684\u81ea\u7136\u5bf9\u6570\u4f1a\u5f15\u53d1<code>ValueError<\/code>\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u4e2a\u95ee\u9898\uff0c\u5efa\u8bae\u5728\u8ba1\u7b97\u4e4b\u524d\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff0c\u786e\u4fdd\u8f93\u5165\u7684\u503c\u662f\u6b63\u6570\u3002\u53ef\u4ee5\u4f7f\u7528<code>if<\/code>\u8bed\u53e5\u6765\u68c0\u67e5\u8f93\u5165\u503c\u7684\u6709\u6548\u6027\uff0c\u5e76\u63d0\u4f9b\u5408\u9002\u7684\u9519\u8bef\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8868\u793a\u81ea\u7136\u5bf9\u6570\u51fd\u6570\uff08ln\uff09\u7684\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528math\u5e93\u4e2d\u7684log\u51fd\u6570\u3001numpy\u5e93\u4e2d\u7684log\u51fd\u6570\u3001 [&hellip;]","protected":false},"author":3,"featured_media":997841,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/997828"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=997828"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/997828\/revisions"}],"predecessor-version":[{"id":997843,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/997828\/revisions\/997843"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/997841"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=997828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=997828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=997828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}