{"id":1024926,"date":"2024-12-30T14:18:04","date_gmt":"2024-12-30T06:18:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1024926.html"},"modified":"2024-12-30T14:18:06","modified_gmt":"2024-12-30T06:18:06","slug":"python%e5%a6%82%e4%bd%95%e7%94%a8log%e5%87%bd%e6%95%b0-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1024926.html","title":{"rendered":"python\u5982\u4f55\u7528log\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/b781669d-cd21-4b78-b399-22fedd018d00.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u7528log\u51fd\u6570\" \/><\/p>\n<p><p> <strong>Python\u4e2d\u4f7f\u7528log\u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u7684math\u5e93\u6765\u5b9e\u73b0\u3001\u4e5f\u53ef\u4ee5\u901a\u8fc7numpy\u5e93\u8fdb\u884c\u8ba1\u7b97\u3001log\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u6570\u503c\u7684\u5bf9\u6570\u3002<\/strong>\u5728Python\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>math.log()<\/code>\u6216<code>numpy.log()<\/code>\u6765\u8ba1\u7b97\u6570\u503c\u7684\u5bf9\u6570\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u6765\u8ba1\u7b97\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001Python\u4e2d\u4f7f\u7528math\u5e93\u7684log\u51fd\u6570<\/h3>\n<\/p>\n<p><p>Python\u7684math\u5e93\u63d0\u4f9b\u4e86\u591a\u79cd\u6570\u5b66\u51fd\u6570\uff0c\u5176\u4e2d\u5305\u62ec<code>math.log()<\/code>\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u8ba1\u7b97\u4efb\u610f\u6570\u503c\u7684\u5bf9\u6570\uff0c\u9ed8\u8ba4\u57fa\u5e95\u4e3a\u81ea\u7136\u5bf9\u6570\uff08\u5373\u4ee5e\u4e3a\u5e95\uff09\uff0c\u4f46\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6765\u8ba1\u7b97\u5176\u4ed6\u57fa\u5e95\u7684\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5bfc\u5165math\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>math.log()<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u5bf9\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/p>\n<p>result = math.log(10)<\/p>\n<p>print(&quot;10\u7684\u81ea\u7136\u5bf9\u6570\u662f\uff1a&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa10\u7684\u81ea\u7136\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u6307\u5b9a\u57fa\u5e95<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u60f3\u8ba1\u7b97\u5176\u4ed6\u57fa\u5e95\u7684\u5bf9\u6570\uff0c\u53ef\u4ee5\u4f20\u9012\u7b2c\u4e8c\u4e2a\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u8981\u8ba1\u7b97\u4ee52\u4e3a\u5e95\u7684\u5bf9\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u4ee52\u4e3a\u5e95\u7684\u5bf9\u6570<\/p>\n<p>result = math.log(10, 2)<\/p>\n<p>print(&quot;10\u7684\u4ee52\u4e3a\u5e95\u7684\u5bf9\u6570\u662f\uff1a&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa10\u4ee52\u4e3a\u5e95\u7684\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001Python\u4e2d\u4f7f\u7528numpy\u5e93\u7684log\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u9664\u4e86math\u5e93\uff0cnumpy\u5e93\u4e5f\u63d0\u4f9b\u4e86\u8ba1\u7b97\u5bf9\u6570\u7684\u51fd\u6570\u3002numpy\u5e93\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u901a\u5e38\u7528\u4e8e\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u5e76\u5bfc\u5165numpy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>numpy.log()<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u81ea\u7136\u5bf9\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u81ea\u7136\u5bf9\u6570<\/p>\n<p>result = np.log(10)<\/p>\n<p>print(&quot;10\u7684\u81ea\u7136\u5bf9\u6570\u662f\uff1a&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa10\u7684\u81ea\u7136\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u6307\u5b9a\u57fa\u5e95<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u60f3\u8ba1\u7b97\u5176\u4ed6\u57fa\u5e95\u7684\u5bf9\u6570\uff0cnumpy\u5e93\u4e5f\u63d0\u4f9b\u4e86<code>numpy.log2()<\/code>\u548c<code>numpy.log10()<\/code>\u51fd\u6570\uff0c\u5206\u522b\u7528\u4e8e\u8ba1\u7b97\u4ee52\u548c10\u4e3a\u5e95\u7684\u5bf9\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u4ee52\u4e3a\u5e95\u7684\u5bf9\u6570<\/p>\n<p>result = np.log2(10)<\/p>\n<p>print(&quot;10\u7684\u4ee52\u4e3a\u5e95\u7684\u5bf9\u6570\u662f\uff1a&quot;, result)<\/p>\n<h2><strong>\u8ba1\u7b97\u4ee510\u4e3a\u5e95\u7684\u5bf9\u6570<\/strong><\/h2>\n<p>result = np.log10(10)<\/p>\n<p>print(&quot;10\u7684\u4ee510\u4e3a\u5e95\u7684\u5bf9\u6570\u662f\uff1a&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u5206\u522b\u8f93\u51fa10\u4ee52\u548c10\u4e3a\u5e95\u7684\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528log\u51fd\u6570\u5904\u7406\u6570\u7ec4<\/h3>\n<\/p>\n<p><p>numpy\u5e93\u7684\u4e00\u4e2a\u5f3a\u5927\u529f\u80fd\u662f\u80fd\u591f\u5bf9\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>numpy.log()<\/code>\u51fd\u6570\u5bf9\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u8ba1\u7b97\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<\/p>\n<p>array = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u81ea\u7136\u5bf9\u6570<\/strong><\/h2>\n<p>result = np.log(array)<\/p>\n<p>print(&quot;\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u81ea\u7136\u5bf9\u6570\uff1a&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u81ea\u7136\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001log\u51fd\u6570\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><h4>1\u3001\u6570\u636e\u6807\u51c6\u5316<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4e2d\uff0c\u6570\u636e\u6807\u51c6\u5316\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u6b65\u9aa4\u3002\u5bf9\u6570\u53d8\u6362\u662f\u4e00\u79cd\u5e38\u7528\u7684\u6570\u636e\u6807\u51c6\u5316\u65b9\u6cd5\uff0c\u7279\u522b\u662f\u5f53\u6570\u636e\u5177\u6709\u8f83\u5927\u7684\u8303\u56f4\u6216\u5b58\u5728\u6781\u7aef\u503c\u65f6\u3002\u901a\u8fc7\u5bf9\u6570\u636e\u8fdb\u884c\u5bf9\u6570\u53d8\u6362\uff0c\u53ef\u4ee5\u51cf\u5c0f\u6570\u636e\u7684\u8303\u56f4\uff0c\u4f7f\u5f97\u6570\u636e\u5206\u5e03\u66f4\u52a0\u5747\u5300\uff0c\u4ece\u800c\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4fe1\u606f\u71b5\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>\u4fe1\u606f\u71b5\u662f\u4fe1\u606f\u8bba\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u6982\u5ff5\uff0c\u7528\u4e8e\u8861\u91cf\u968f\u673a\u53d8\u91cf\u7684\u4e0d\u786e\u5b9a\u6027\u3002\u5728\u8ba1\u7b97\u4fe1\u606f\u71b5\u65f6\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528\u5bf9\u6570\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u5728\u8ba1\u7b97\u79bb\u6563\u968f\u673a\u53d8\u91cf\u7684\u71b5\u65f6\uff0c\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>[ H(X) = -\\sum_{i} p(x_i) \\log p(x_i) ]<\/p>\n<p>\u5176\u4e2d\uff0c( p(x_i) )\u8868\u793a\u968f\u673a\u53d8\u91cf\u53d6\u503c( x_i )\u7684\u6982\u7387\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u635f\u5931\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5728\u4e00\u4e9b\u673a\u5668\u5b66\u4e60\u6a21\u578b\u4e2d\uff0c\u635f\u5931\u51fd\u6570\u4e2d\u4e5f\u4f1a\u4f7f\u7528\u5bf9\u6570\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u4ea4\u53c9\u71b5\u635f\u5931\u51fd\u6570\uff08Cross-Entropy Loss\uff09\u7528\u4e8e\u5206\u7c7b\u95ee\u9898\u4e2d\uff0c\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>[ L(y, \\hat{y}) = -\\sum_{i} y_i \\log(\\hat{y}_i) ]<\/p>\n<p>\u5176\u4e2d\uff0c( y_i )\u8868\u793a\u771f\u5b9e\u6807\u7b7e\uff0c( \\hat{y}_i )\u8868\u793a\u6a21\u578b\u9884\u6d4b\u7684\u6982\u7387\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5904\u7406\u7279\u6b8a\u60c5\u51b5<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528log\u51fd\u6570\u65f6\uff0c\u6709\u4e00\u4e9b\u7279\u6b8a\u60c5\u51b5\u9700\u8981\u6ce8\u610f\u3002\u4f8b\u5982\uff0c\u5f53\u8f93\u5165\u503c\u4e3a\u8d1f\u6570\u6216\u96f6\u65f6\uff0clog\u51fd\u6570\u5c06\u8fd4\u56deNaN\uff08Not a Number\uff09\u6216\u5f15\u53d1\u9519\u8bef\u3002\u8fd9\u662f\u56e0\u4e3a\u5bf9\u6570\u51fd\u6570\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\u662f\u672a\u5b9a\u4e49\u7684\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u5904\u7406\u8fd9\u4e9b\u7279\u6b8a\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\u6765\u68c0\u67e5\u8f93\u5165\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u5bf9\u6570\uff0c\u5e76\u5904\u7406\u7279\u6b8a\u60c5\u51b5<\/p>\n<p>def <a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>_log(x, base=math.e):<\/p>\n<p>    if x &lt;= 0:<\/p>\n<p>        return float(&#39;nan&#39;)  # \u8fd4\u56deNaN<\/p>\n<p>    else:<\/p>\n<p>        return math.log(x, base)<\/p>\n<h2><strong>\u6d4b\u8bd5\u51fd\u6570<\/strong><\/h2>\n<p>result = safe_log(-10)<\/p>\n<p>print(&quot;\u7ed3\u679c\uff1a&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51faNaN\uff0c\u56e0\u4e3a\u8f93\u5165\u503c\u4e3a\u8d1f\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u6027\u80fd\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u6027\u80fd\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\u3002numpy\u5e93\u7684\u5411\u91cf\u5316\u64cd\u4f5c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u8ba1\u7b97\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u5229\u7528\u4e86\u5e95\u5c42\u7684\u9ad8\u6548\u5b9e\u73b0\u3002\u5982\u679c\u4f60\u9700\u8981\u5bf9\u5927\u91cf\u6570\u636e\u8fdb\u884c\u5bf9\u6570\u53d8\u6362\uff0c\u5efa\u8bae\u4f7f\u7528numpy\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5927\u89c4\u6a21\u6570\u7ec4<\/p>\n<p>large_array = np.random.rand(1000000)<\/p>\n<h2><strong>\u4f7f\u7528numpy\u8ba1\u7b97\u5bf9\u6570<\/strong><\/h2>\n<p>result = np.log(large_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u9ad8\u6548\u5730\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5bf9\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528log\u51fd\u6570\u6765\u8ba1\u7b97\u5bf9\u6570\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684math\u5e93\u6216\u5f3a\u5927\u7684numpy\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002math\u5e93\u9002\u7528\u4e8e\u7b80\u5355\u7684\u5bf9\u6570\u8ba1\u7b97\uff0c\u800cnumpy\u5e93\u5219\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u5904\u7406\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u4ecb\u7ecd\u4e86log\u51fd\u6570\u7684\u4e00\u4e9b\u5e94\u7528\u573a\u666f\u548c\u5904\u7406\u7279\u6b8a\u60c5\u51b5\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u662f\u5728\u6570\u636e\u79d1\u5b66\u3001\u673a\u5668\u5b66\u4e60\u8fd8\u662f\u5176\u4ed6\u9886\u57df\uff0c\u5bf9\u6570\u51fd\u6570\u90fd\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u5de5\u5177\u3002\u901a\u8fc7\u638c\u63e1log\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u5904\u7406\u548c\u5206\u6790\u6570\u636e\uff0c\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Python\u4e2d\u7684log\u51fd\u6570\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528log\u51fd\u6570\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0clog\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u6570\u5b57\u7684\u5bf9\u6570\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684math\u6a21\u5757\u6765\u8c03\u7528log\u51fd\u6570\u3002\u5b83\u7684\u57fa\u672c\u7528\u6cd5\u4e3a<code>math.log(x, base)<\/code>\uff0c\u5176\u4e2d<code>x<\/code>\u662f\u4f60\u60f3\u8ba1\u7b97\u5bf9\u6570\u7684\u6570\u5b57\uff0c\u800c<code>base<\/code>\u662f\u5bf9\u6570\u7684\u5e95\u6570\u3002\u5982\u679c\u5e95\u6570\u7701\u7565\uff0c\u9ed8\u8ba4\u4f7f\u7528\u81ea\u7136\u5bf9\u6570\uff08\u5e95\u6570\u4e3ae\uff09\u3002\u4f8b\u5982\uff0c<code>math.log(10)<\/code>\u4f1a\u8fd4\u56de10\u7684\u81ea\u7136\u5bf9\u6570\uff0c\u800c<code>math.log(100, 10)<\/code>\u4f1a\u8fd4\u56de100\u4ee510\u4e3a\u5e95\u7684\u5bf9\u6570\u3002<\/p>\n<p><strong>Python\u7684log\u51fd\u6570\u652f\u6301\u54ea\u4e9b\u5e95\u6570\uff1f<\/strong><br \/>Python\u4e2d\u7684log\u51fd\u6570\u53ef\u4ee5\u652f\u6301\u4efb\u610f\u6b63\u6570\u4f5c\u4e3a\u5e95\u6570\u3002\u5e38\u89c1\u7684\u5e95\u6570\u5305\u62ec10\uff08\u5e38\u7528\u5bf9\u6570\uff09\uff0ce\uff08\u81ea\u7136\u5bf9\u6570\uff09\u548c2\uff08\u4e8c\u8fdb\u5236\u5bf9\u6570\uff09\u3002\u4f7f\u7528\u8fd9\u4e9b\u5e95\u6570\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u4e0d\u540c\u7684\u6570\u5b66\u548c\u5de5\u7a0b\u5e94\u7528\u4e2d\u8fdb\u884c\u8ba1\u7b97\u3002\u4f8b\u5982\uff0c<code>math.log(8, 2)<\/code>\u53ef\u4ee5\u8ba1\u7b978\u4ee52\u4e3a\u5e95\u7684\u5bf9\u6570\uff0c\u7ed3\u679c\u4e3a3\uff0c\u56e0\u4e3a2\u76843\u6b21\u65b9\u7b49\u4e8e8\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406log\u51fd\u6570\u4e2d\u7684\u8d1f\u6570\u6216\u96f6\u503c\uff1f<\/strong><br \/>\u5728\u4f7f\u7528log\u51fd\u6570\u65f6\uff0c\u5fc5\u987b\u6ce8\u610f\u8f93\u5165\u503c\u7684\u9650\u5236\u3002log\u51fd\u6570\u7684\u8f93\u5165\u503c\u5fc5\u987b\u662f\u6b63\u6570\u3002\u5982\u679c\u5c1d\u8bd5\u8ba1\u7b970\u6216\u8d1f\u6570\u7684\u5bf9\u6570\uff0cPython\u4f1a\u629b\u51faValueError\u5f02\u5e38\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u5efa\u8bae\u5728\u8fdb\u884c\u8ba1\u7b97\u4e4b\u524d\u5bf9\u8f93\u5165\u503c\u8fdb\u884c\u68c0\u67e5\uff0c\u786e\u4fdd\u5b83\u4eec\u4e3a\u6b63\u503c\u3002\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\u6765\u5904\u7406\u8fd9\u4e9b\u60c5\u51b5\uff0c\u4ece\u800c\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u4f7f\u7528log\u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u7684math\u5e93\u6765\u5b9e\u73b0\u3001\u4e5f\u53ef\u4ee5\u901a\u8fc7numpy\u5e93\u8fdb\u884c\u8ba1\u7b97\u3001log\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97 [&hellip;]","protected":false},"author":3,"featured_media":1024929,"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\/1024926"}],"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=1024926"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1024926\/revisions"}],"predecessor-version":[{"id":1024930,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1024926\/revisions\/1024930"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1024929"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1024926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1024926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1024926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}