{"id":1028216,"date":"2024-12-31T10:57:40","date_gmt":"2024-12-31T02:57:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1028216.html"},"modified":"2024-12-31T10:57:43","modified_gmt":"2024-12-31T02:57:43","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%bc%80%e5%b9%b3%e6%96%b9%e6%a0%b9","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1028216.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u5f00\u5e73\u65b9\u6839"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/591f7cec-8f19-4db3-b811-06a535b96383.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u4e2d\u5982\u4f55\u5f00\u5e73\u65b9\u6839\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u5f00\u5e73\u65b9\u6839\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528<code>math<\/code>\u6a21\u5757\u3001<code>cmath<\/code>\u6a21\u5757\uff08\u7528\u4e8e\u5904\u7406\u590d\u6570\uff09\u3001<code>numpy<\/code>\u5e93\u4ee5\u53ca\u76f4\u63a5\u4f7f\u7528\u5e42\u8fd0\u7b97\u7b26\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>1. \u4f7f\u7528math\u6a21\u5757<\/strong><\/p>\n<p>Python\u7684<code>math<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3a<code>sqrt<\/code>\u7684\u65b9\u6cd5\u6765\u8ba1\u7b97\u5e73\u65b9\u6839\u3002\u8fd9\u4e2a\u65b9\u6cd5\u9002\u7528\u4e8e\u5904\u7406\u6d6e\u70b9\u6570\uff0c\u5e76\u4e14\u6548\u7387\u5f88\u9ad8\u3002\u4f7f\u7528<code>math.sqrt()<\/code>\u662f\u6700\u5e38\u89c1\u548c\u63a8\u8350\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u4e14\u6e05\u6670\u3002  <\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u4f7f\u7528math.sqrt()\u8ba1\u7b97\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>num = 16<\/p>\n<p>sqrt_num = math.sqrt(num)<\/p>\n<p>print(&quot;The square root of&quot;, num, &quot;is&quot;, sqrt_num)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>2. \u4f7f\u7528\u5e42\u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5e42\u8fd0\u7b97\u7b26<code><\/code>\u6765\u8ba1\u7b97\u5e73\u65b9\u6839\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u57fa\u7840\u6570\u5b66\u8fd0\u7b97\uff0c\u4f46\u5bf9\u4e8e\u5904\u7406\u590d\u6570\u6216\u66f4\u590d\u6742\u7684\u6570\u503c\u8ba1\u7b97\uff0c\u8fd8\u662f\u63a8\u8350\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u3002  <\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5e42\u8fd0\u7b97\u7b26\u8ba1\u7b97\u5e73\u65b9\u6839<\/p>\n<p>num = 16<\/p>\n<p>sqrt_num = num  0.5<\/p>\n<p>print(&quot;The square root of&quot;, num, &quot;is&quot;, sqrt_num)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>3. \u4f7f\u7528cmath\u6a21\u5757<\/strong><\/p>\n<p>\u5982\u679c\u9700\u8981\u5904\u7406\u590d\u6570\u7684\u5e73\u65b9\u6839\uff0c\u53ef\u4ee5\u4f7f\u7528<code>cmath<\/code>\u6a21\u5757\u3002<code>cmath<\/code>\u6a21\u5757\u4e5f\u63d0\u4f9b\u4e86<code>sqrt<\/code>\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u8ba1\u7b97\u590d\u6570\u7684\u5e73\u65b9\u6839\u3002  <\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cmath<\/p>\n<h2><strong>\u4f7f\u7528cmath.sqrt()\u8ba1\u7b97\u590d\u6570\u7684\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>num = -16<\/p>\n<p>sqrt_num = cmath.sqrt(num)<\/p>\n<p>print(&quot;The square root of&quot;, num, &quot;is&quot;, sqrt_num)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>4. \u4f7f\u7528numpy\u5e93<\/strong><\/p>\n<p>\u5bf9\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\uff0c<code>numpy<\/code>\u5e93\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\u3002<code>numpy<\/code>\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3a<code>sqrt<\/code>\u7684\u65b9\u6cd5\u6765\u8ba1\u7b97\u5e73\u65b9\u6839\uff0c\u9002\u7528\u4e8e\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u3002  <\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u4f7f\u7528numpy.sqrt()\u8ba1\u7b97\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>num_array = np.array([16, 25, 36])<\/p>\n<p>sqrt_array = np.sqrt(num_array)<\/p>\n<p>print(&quot;The square roots are:&quot;, sqrt_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e00\u3001math\u6a21\u5757<\/h3>\n<\/p>\n<p><p>Python\u7684<code>math<\/code>\u6a21\u5757\u662f\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u7528\u4e8e\u6570\u5b66\u8fd0\u7b97\u7684\u51fd\u6570\uff0c\u5176\u4e2d\u5305\u62ec<code>sqrt<\/code>\u51fd\u6570\uff0c\u7528\u4e8e\u8ba1\u7b97\u975e\u8d1f\u6570\u7684\u5e73\u65b9\u6839\u3002<code>math.sqrt()<\/code>\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u7b80\u5355\u6027\u548c\u9ad8\u6548\u6027\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528math.sqrt()\u8ba1\u7b97\u5e73\u65b9\u6839<\/h4>\n<\/p>\n<p><p><code>math.sqrt(x)<\/code>\u8fd4\u56dex\u7684\u5e73\u65b9\u6839\uff0c\u5176\u4e2dx\u5fc5\u987b\u662f\u975e\u8d1f\u6570\uff0c\u5426\u5219\u4f1a\u5f15\u53d1<code>ValueError<\/code>\u3002\u8fd9\u4e2a\u65b9\u6cd5\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u7684\u5e73\u65b9\u6839\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u8ba1\u7b97\u4e00\u4e2a\u6b63\u6570\u7684\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>num = 25<\/p>\n<p>sqrt_num = math.sqrt(num)<\/p>\n<p>print(f&quot;The square root of {num} is {sqrt_num}&quot;)<\/p>\n<h2><strong>\u5c1d\u8bd5\u8ba1\u7b97\u4e00\u4e2a\u8d1f\u6570\u7684\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>try:<\/p>\n<p>    num = -25<\/p>\n<p>    sqrt_num = math.sqrt(num)<\/p>\n<p>except ValueError as e:<\/p>\n<p>    print(f&quot;Error: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>math.sqrt()\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<p><p><code>math.sqrt()<\/code>\u9002\u7528\u4e8e\u9700\u8981\u5feb\u901f\u3001\u51c6\u786e\u8ba1\u7b97\u975e\u8d1f\u6570\u5e73\u65b9\u6839\u7684\u60c5\u51b5\u3002\u5b83\u5e38\u7528\u4e8e\u51e0\u4f55\u8ba1\u7b97\u3001\u7269\u7406\u6a21\u62df\u548c\u5de5\u7a0b\u5e94\u7528\u4e2d\u3002\u4f8b\u5982\uff0c\u5728\u8ba1\u7b97\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u3001\u7269\u4f53\u7684\u81ea\u7531\u843d\u4f53\u65f6\u95f4\u7b49\u65b9\u9762\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528<code>math.sqrt()<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5e42\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u7684\u5e42\u8fd0\u7b97\u7b26<code>&lt;strong&gt;<\/code>\u53ef\u4ee5\u7528\u4e8e\u8ba1\u7b97\u4efb\u4f55\u6570\u7684\u5e42\u6b21\u65b9\uff0c\u5305\u62ec\u5e73\u65b9\u6839\u3002\u5bf9\u4e8e\u4e00\u4e2a\u6570<code>x<\/code>\uff0c\u5b83\u7684\u5e73\u65b9\u6839\u53ef\u4ee5\u8868\u793a\u4e3a<code>x &lt;\/strong&gt; 0.5<\/code>\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u5e42\u8fd0\u7b97\u7b26\u8ba1\u7b97\u5e73\u65b9\u6839<\/h4>\n<\/p>\n<p><p>\u5e42\u8fd0\u7b97\u7b26\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u901a\u7528\u6027\u548c\u7b80\u6d01\u6027\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5bf9\u4e8e\u8d1f\u6570\u7684\u5e73\u65b9\u6839\uff0c\u5b83\u4f1a\u8fd4\u56de\u4e00\u4e2a\u590d\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u4e00\u4e2a\u6b63\u6570\u7684\u5e73\u65b9\u6839<\/p>\n<p>num = 16<\/p>\n<p>sqrt_num = num  0.5<\/p>\n<p>print(f&quot;The square root of {num} is {sqrt_num}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u4e00\u4e2a\u8d1f\u6570\u7684\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>num = -16<\/p>\n<p>sqrt_num = num  0.5<\/p>\n<p>print(f&quot;The square root of {num} is {sqrt_num}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5e42\u8fd0\u7b97\u7b26\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<p><p>\u5e42\u8fd0\u7b97\u7b26\u9002\u7528\u4e8e\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\uff0c\u7279\u522b\u662f\u5f53\u4f60\u5df2\u7ecf\u5728\u4f7f\u7528\u5176\u4ed6\u6570\u5b66\u8fd0\u7b97\u7b26\u65f6\u3002\u5b83\u7684\u8bed\u6cd5\u7b80\u5355\uff0c\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\u3002\u5bf9\u4e8e\u79d1\u5b66\u8ba1\u7b97\u6216\u9700\u8981\u5904\u7406\u590d\u6570\u7684\u60c5\u51b5\uff0c\u5efa\u8bae\u4f7f\u7528\u5176\u4ed6\u66f4\u4e13\u4e1a\u7684\u5e93\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001cmath\u6a21\u5757<\/h3>\n<\/p>\n<p><p><code>cmath<\/code>\u6a21\u5757\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u590d\u6570\u7684\u6570\u5b66\u8fd0\u7b97\u3002\u4e0e<code>math<\/code>\u6a21\u5757\u4e0d\u540c\uff0c<code>cmath<\/code>\u6a21\u5757\u53ef\u4ee5\u5904\u7406\u590d\u6570\u7684\u5e73\u65b9\u6839\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528cmath.sqrt()\u8ba1\u7b97\u590d\u6570\u7684\u5e73\u65b9\u6839<\/h4>\n<\/p>\n<p><p><code>cmath.sqrt(x)<\/code>\u8fd4\u56de\u590d\u6570x\u7684\u5e73\u65b9\u6839\u3002\u5373\u4f7fx\u662f\u8d1f\u6570\uff0c\u5b83\u4e5f\u80fd\u6b63\u786e\u5904\u7406\u5e76\u8fd4\u56de\u4e00\u4e2a\u590d\u6570\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cmath<\/p>\n<h2><strong>\u8ba1\u7b97\u4e00\u4e2a\u6b63\u6570\u7684\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>num = 25<\/p>\n<p>sqrt_num = cmath.sqrt(num)<\/p>\n<p>print(f&quot;The square root of {num} is {sqrt_num}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u4e00\u4e2a\u8d1f\u6570\u7684\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>num = -25<\/p>\n<p>sqrt_num = cmath.sqrt(num)<\/p>\n<p>print(f&quot;The square root of {num} is {sqrt_num}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>cmath.sqrt()\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<p><p><code>cmath.sqrt()<\/code>\u9002\u7528\u4e8e\u9700\u8981\u5904\u7406\u590d\u6570\u8fd0\u7b97\u7684\u60c5\u51b5\uff0c\u5982\u7535\u8def\u5206\u6790\u3001\u4fe1\u53f7\u5904\u7406\u548c\u91cf\u5b50\u529b\u5b66\u7b49\u9886\u57df\u3002\u5728\u8fd9\u4e9b\u9886\u57df\u4e2d\uff0c\u590d\u6570\u8fd0\u7b97\u662f\u975e\u5e38\u5e38\u89c1\u7684\uff0c\u56e0\u6b64<code>cmath<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001numpy\u5e93<\/h3>\n<\/p>\n<p><p><code>numpy<\/code>\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u548c\u79d1\u5b66\u8ba1\u7b97\u9886\u57df\u3002<code>numpy<\/code>\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\uff0c\u5305\u62ec<code>sqrt<\/code>\u51fd\u6570\uff0c\u7528\u4e8e\u8ba1\u7b97\u6570\u7ec4\u6216\u77e9\u9635\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5e73\u65b9\u6839\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528numpy.sqrt()\u8ba1\u7b97\u6570\u7ec4\u7684\u5e73\u65b9\u6839<\/h4>\n<\/p>\n<p><p><code>numpy.sqrt(x)<\/code>\u8fd4\u56de\u6570\u7ec4x\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5e73\u65b9\u6839\u3002\u5b83\u652f\u6301\u5927\u89c4\u6a21\u6570\u636e\u5904\u7406\uff0c\u975e\u5e38\u9002\u5408\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6570\u5b57\u7684\u6570\u7ec4<\/strong><\/h2>\n<p>num_array = np.array([16, 25, 36])<\/p>\n<p>sqrt_array = np.sqrt(num_array)<\/p>\n<p>print(&quot;The square roots are:&quot;, sqrt_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>numpy.sqrt()\u7684\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<p><p><code>numpy.sqrt()<\/code>\u9002\u7528\u4e8e\u9700\u8981\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u6216\u8fdb\u884c\u79d1\u5b66\u8ba1\u7b97\u7684\u60c5\u51b5\u3002\u5b83\u7684\u9ad8\u6548\u6027\u548c\u7075\u6d3b\u6027\u4f7f\u5176\u6210\u4e3a\u6570\u636e\u79d1\u5b66\u5bb6\u548c\u7814\u7a76\u4eba\u5458\u7684\u9996\u9009\u5de5\u5177\u3002\u7279\u522b\u662f\u5728\u673a\u5668\u5b66\u4e60\u3001\u7edf\u8ba1\u5206\u6790\u548c\u7269\u7406\u6a21\u62df\u4e2d\uff0c<code>numpy<\/code>\u7684\u529f\u80fd\u975e\u5e38\u5f3a\u5927\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5f00\u5e73\u65b9\u6839\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>math\u6a21\u5757\uff1a<\/strong> \u9002\u7528\u4e8e\u5904\u7406\u975e\u8d1f\u6570\u7684\u5e73\u65b9\u6839\uff0c\u7b80\u5355\u4e14\u9ad8\u6548\u3002<\/li>\n<li><strong>\u5e42\u8fd0\u7b97\u7b26\uff1a<\/strong> \u9002\u7528\u4e8e\u57fa\u7840\u6570\u5b66\u8fd0\u7b97\uff0c\u8bed\u6cd5\u7b80\u5355\uff0c\u4f46\u5904\u7406\u8d1f\u6570\u65f6\u9700\u6ce8\u610f\u3002<\/li>\n<li><strong>cmath\u6a21\u5757\uff1a<\/strong> \u9002\u7528\u4e8e\u5904\u7406\u590d\u6570\u7684\u5e73\u65b9\u6839\uff0c\u5e38\u7528\u4e8e\u7535\u8def\u5206\u6790\u548c\u4fe1\u53f7\u5904\u7406\u3002<\/li>\n<li><strong>numpy\u5e93\uff1a<\/strong> \u9002\u7528\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u548c\u79d1\u5b66\u8ba1\u7b97\uff0c\u529f\u80fd\u5f3a\u5927\u4e14\u9ad8\u6548\u3002<\/li>\n<\/ul>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u80fd\u5728Python\u4e2d\u65b9\u4fbf\u5730\u8ba1\u7b97\u5e73\u65b9\u6839\uff0c\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8ba1\u7b97\u5e73\u65b9\u6839\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u8ba1\u7b97\u5e73\u65b9\u6839\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528\u5185\u7f6e\u7684<code>math<\/code>\u6a21\u5757\u3002\u901a\u8fc7\u5bfc\u5165<code>math<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528<code>math.sqrt()<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u4e00\u4e2a\u6570\u7684\u5e73\u65b9\u6839\u3002\u4f8b\u5982\uff0c<code>import math<\/code>\u540e\uff0c\u4f7f\u7528<code>math.sqrt(16)<\/code>\u5c06\u8fd4\u56de4.0\uff0c\u8868\u793a16\u7684\u5e73\u65b9\u6839\u662f4\u3002\u6b64\u5916\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>&lt;strong&gt;<\/code>\u8fd0\u7b97\u7b26\u6765\u8ba1\u7b97\u5e73\u65b9\u6839\uff0c\u4f8b\u5982<code>16 &lt;\/strong&gt; 0.5<\/code>\u4e5f\u4f1a\u8fd4\u56de4.0\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u8ba1\u7b97\u5e73\u65b9\u6839\uff1f<\/strong><br \/>\u9664\u4e86<code>math.sqrt()<\/code>\u51fd\u6570\uff0cPython\u8fd8\u652f\u6301\u4f7f\u7528<code>numpy<\/code>\u5e93\u6765\u8ba1\u7b97\u5e73\u65b9\u6839\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u3002\u901a\u8fc7<code>numpy.sqrt()<\/code>\uff0c\u53ef\u4ee5\u5bf9\u6574\u4e2a\u6570\u7ec4\u8fdb\u884c\u5e73\u65b9\u6839\u8ba1\u7b97\uff0c\u8fd4\u56de\u76f8\u5e94\u7684\u7ed3\u679c\u3002\u4f8b\u5982\uff0c<code>import numpy as np<\/code>\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>np.sqrt([1, 4, 9])<\/code>\u5f97\u5230\u4e00\u4e2a\u6570\u7ec4<code>[1.0, 2.0, 3.0]<\/code>\uff0c\u8868\u793a\u6bcf\u4e2a\u5143\u7d20\u7684\u5e73\u65b9\u6839\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5f00\u5e73\u65b9\u6839\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u8ba1\u7b97\u5e73\u65b9\u6839\u65f6\uff0c\u8f93\u5165\u7684\u503c\u5fc5\u987b\u662f\u975e\u8d1f\u6570\u3002\u5982\u679c\u5c1d\u8bd5\u8ba1\u7b97\u8d1f\u6570\u7684\u5e73\u65b9\u6839\uff0c<code>math.sqrt()<\/code>\u4f1a\u5f15\u53d1<code>ValueError<\/code>\u3002\u5982\u679c\u5e0c\u671b\u5904\u7406\u8d1f\u6570\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u590d\u6570\uff0c\u4f8b\u5982<code>complex(-1)**0.5<\/code>\uff0c\u8fd9\u5c06\u8fd4\u56de\u865a\u6570\u5355\u4f4d<code>i<\/code>\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u5728\u4f7f\u7528<code>numpy<\/code>\u65f6\uff0c\u8f93\u5165\u7684\u6570\u7ec4\u4e5f\u5e94\u907f\u514d\u5305\u542b\u8d1f\u6570\uff0c\u4ee5\u9632\u6b62\u4ea7\u751f\u9519\u8bef\u6216\u8b66\u544a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u5f00\u5e73\u65b9\u6839\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528math\u6a21\u5757\u3001cmath\u6a21\u5757\uff08\u7528\u4e8e\u5904\u7406\u590d\u6570\uff09\u3001numpy\u5e93\u4ee5 [&hellip;]","protected":false},"author":3,"featured_media":1028231,"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\/1028216"}],"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=1028216"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1028216\/revisions"}],"predecessor-version":[{"id":1028236,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1028216\/revisions\/1028236"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1028231"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1028216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1028216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1028216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}