{"id":1036734,"date":"2024-12-31T12:09:18","date_gmt":"2024-12-31T04:09:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1036734.html"},"modified":"2024-12-31T12:09:20","modified_gmt":"2024-12-31T04:09:20","slug":"python%e5%a6%82%e4%bd%95%e6%b1%82%e6%95%b0%e7%bb%84%e7%9a%84%e5%b9%b3%e5%9d%87%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1036734.html","title":{"rendered":"Python\u5982\u4f55\u6c42\u6570\u7ec4\u7684\u5e73\u5747\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/8014ad01-c3f5-4caf-9e0a-9a1ba4443c5b.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"Python\u5982\u4f55\u6c42\u6570\u7ec4\u7684\u5e73\u5747\u503c\" \/><\/p>\n<p><p> <strong>Python\u6c42\u6570\u7ec4\u5e73\u5747\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd<\/strong>\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u901a\u8fc7\u5faa\u73af\u8ba1\u7b97\u3001\u4f7f\u7528NumPy\u5e93\u7b49\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u4e14\u6709\u6548\u7684\u65b9\u6cd5\u6765\u8ba1\u7b97\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff0c\u5e76\u6df1\u5165\u63a2\u8ba8\u5b83\u4eec\u7684\u5b9e\u73b0\u548c\u5404\u81ea\u7684\u4f18\u7f3a\u70b9\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570sum()\u548clen()<\/p>\n<\/p>\n<p><p>Python\u5185\u7f6e\u7684<code>sum()<\/code>\u548c<code>len()<\/code>\u51fd\u6570\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba1\u7b97\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5c0f\u578b\u6570\u7ec4\uff0c\u4ee3\u7801\u7b80\u5355\u6613\u8bfb\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def average(arr):<\/p>\n<p>    return sum(arr) \/ len(arr)<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>array = [1, 2, 3, 4, 5]<\/p>\n<p>print(&quot;\u5e73\u5747\u503c\u662f\uff1a&quot;, average(array))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u89e3\u91ca\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>sum()\u51fd\u6570<\/strong>\uff1a\u8ba1\u7b97\u6570\u7ec4\u6240\u6709\u5143\u7d20\u7684\u603b\u548c\u3002<\/li>\n<li><strong>len()\u51fd\u6570<\/strong>\uff1a\u8ba1\u7b97\u6570\u7ec4\u7684\u5143\u7d20\u6570\u91cf\u3002<\/li>\n<li><strong>\u5e73\u5747\u503c\u8ba1\u7b97<\/strong>\uff1a\u7528\u603b\u548c\u9664\u4ee5\u5143\u7d20\u6570\u91cf\u5373\u53ef\u5f97\u51fa\u5e73\u5747\u503c\u3002<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528for\u5faa\u73af\u624b\u52a8\u8ba1\u7b97<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u60c5\u51b5\uff0c\u6bd4\u5982\u9700\u8981\u5bf9\u7279\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\u6c42\u5e73\u5747\u503c\uff0c\u4f7f\u7528for\u5faa\u73af\u624b\u52a8\u8ba1\u7b97\u662f\u4e00\u4e2a\u7075\u6d3b\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def average(arr):<\/p>\n<p>    total = 0<\/p>\n<p>    for num in arr:<\/p>\n<p>        total += num<\/p>\n<p>    return total \/ len(arr)<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>array = [1, 2, 3, 4, 5]<\/p>\n<p>print(&quot;\u5e73\u5747\u503c\u662f\uff1a&quot;, average(array))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f<strong>\u7075\u6d3b\u6027\u9ad8<\/strong>\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u590d\u6742\u7684\u6761\u4ef6\u8ba1\u7b97\uff0c\u4f46\u4ee3\u7801\u8f83\u4e3a\u7e41\u7410\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528NumPy\u5e93<\/p>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u65b9\u6cd5\u3002\u4f7f\u7528NumPy\u5e93\u4e2d\u7684<code>mean()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def average(arr):<\/p>\n<p>    return np.mean(arr)<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>array = [1, 2, 3, 4, 5]<\/p>\n<p>print(&quot;\u5e73\u5747\u503c\u662f\uff1a&quot;, average(array))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>\u9ad8\u6548<\/strong>\uff1aNumPy\u5e95\u5c42\u4f7f\u7528C\u8bed\u8a00\u5b9e\u73b0\uff0c\u8ba1\u7b97\u901f\u5ea6\u5feb\u3002<\/li>\n<li><strong>\u7b80\u6d01<\/strong>\uff1a\u4ee3\u7801\u7b80\u6d01\u660e\u4e86\uff0c\u6613\u4e8e\u7ef4\u62a4\u3002<\/li>\n<li><strong>\u529f\u80fd\u4e30\u5bcc<\/strong>\uff1aNumPy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\uff0c\u53ef\u4ee5\u5904\u7406\u66f4\u590d\u6742\u7684\u6570\u7ec4\u64cd\u4f5c\u3002<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528Pandas\u5e93<\/p>\n<\/p>\n<p><p>Pandas\u662f\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u5e38\u7528\u4e8e\u5904\u7406\u8868\u683c\u6570\u636e\u3002\u4f7f\u7528Pandas\u7684<code>Series<\/code>\u5bf9\u8c61\u548c<code>mean()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba1\u7b97\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>def average(arr):<\/p>\n<p>    return pd.Series(arr).mean()<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>array = [1, 2, 3, 4, 5]<\/p>\n<p>print(&quot;\u5e73\u5747\u503c\u662f\uff1a&quot;, average(array))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>\u9002\u7528\u4e8e\u5927\u6570\u636e\u96c6<\/strong>\uff1aPandas\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\u8868\u73b0\u4f18\u5f02\u3002<\/li>\n<li><strong>\u4e30\u5bcc\u7684\u6570\u636e\u5206\u6790\u529f\u80fd<\/strong>\uff1a\u9664\u4e86\u8ba1\u7b97\u5e73\u5747\u503c\uff0cPandas\u8fd8\u63d0\u4f9b\u4e86\u5f88\u591a\u5176\u4ed6\u6570\u636e\u5206\u6790\u529f\u80fd\u3002<\/li>\n<li><strong>\u4e0e\u5176\u4ed6\u5e93\u96c6\u6210\u826f\u597d<\/strong>\uff1aPandas\u53ef\u4ee5\u4e0eNumPy\u3001Matplotlib\u7b49\u5e93\u65e0\u7f1d\u96c6\u6210\u3002<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u8003\u8651\u6570\u636e\u6e05\u6d17\u548c\u9884\u5904\u7406<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6570\u636e\u5f80\u5f80\u4e0d\u90a3\u4e48\u5e72\u51c0\uff0c\u53ef\u80fd\u5305\u542b\u7f3a\u5931\u503c\u3001\u5f02\u5e38\u503c\u7b49\u3002\u5728\u8ba1\u7b97\u5e73\u5747\u503c\u4e4b\u524d\uff0c\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u548c\u9884\u5904\u7406\u662f\u5fc5\u8981\u7684\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def clean_and_average(arr):<\/p>\n<p>    cleaned_arr = [x for x in arr if not np.isnan(x) and x &gt;= 0]  # \u53bb\u9664NaN\u503c\u548c\u8d1f\u503c<\/p>\n<p>    return np.mean(cleaned_arr)<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>array = [1, 2, 3, np.nan, 5, -1]<\/p>\n<p>print(&quot;\u6e05\u6d17\u540e\u7684\u5e73\u5747\u503c\u662f\uff1a&quot;, clean_and_average(array))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>\u53bb\u9664\u7f3a\u5931\u503c\uff08NaN\uff09<\/strong>\uff1a\u4f7f\u7528<code>np.isnan()<\/code>\u51fd\u6570\u53bb\u9664NaN\u503c\u3002<\/li>\n<li><strong>\u53bb\u9664\u5f02\u5e38\u503c<\/strong>\uff1a\u6839\u636e\u5177\u4f53\u60c5\u51b5\u53bb\u9664\u8d1f\u503c\u6216\u5176\u4ed6\u5f02\u5e38\u503c\u3002<\/li>\n<li><strong>\u8ba1\u7b97\u5e73\u5747\u503c<\/strong>\uff1a\u5bf9\u6e05\u6d17\u540e\u7684\u6570\u636e\u8ba1\u7b97\u5e73\u5747\u503c\u3002<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u5904\u7406\u591a\u7ef4\u6570\u7ec4<\/p>\n<\/p>\n<p><p>\u5728\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u4e2d\uff0c\u5e38\u5e38\u9700\u8981\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u3002NumPy\u5e93\u63d0\u4f9b\u4e86\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u7684\u5f3a\u5927\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba1\u7b97\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<h2><strong>\u8ba1\u7b97\u6574\u4e2a\u6570\u7ec4\u7684\u5e73\u5747\u503c<\/strong><\/h2>\n<p>overall_average = np.mean(array)<\/p>\n<h2><strong>\u8ba1\u7b97\u6bcf\u4e00\u884c\u7684\u5e73\u5747\u503c<\/strong><\/h2>\n<p>row_averages = np.mean(array, axis=1)<\/p>\n<h2><strong>\u8ba1\u7b97\u6bcf\u4e00\u5217\u7684\u5e73\u5747\u503c<\/strong><\/h2>\n<p>column_averages = np.mean(array, axis=0)<\/p>\n<p>print(&quot;\u6574\u4e2a\u6570\u7ec4\u7684\u5e73\u5747\u503c\u662f\uff1a&quot;, overall_average)<\/p>\n<p>print(&quot;\u6bcf\u4e00\u884c\u7684\u5e73\u5747\u503c\u662f\uff1a&quot;, row_averages)<\/p>\n<p>print(&quot;\u6bcf\u4e00\u5217\u7684\u5e73\u5747\u503c\u662f\uff1a&quot;, column_averages)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>\u8ba1\u7b97\u6574\u4f53\u5e73\u5747\u503c<\/strong>\uff1a\u4f7f\u7528<code>np.mean(array)<\/code>\u8ba1\u7b97\u6574\u4e2a\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002<\/li>\n<li><strong>\u6309\u884c\u8ba1\u7b97\u5e73\u5747\u503c<\/strong>\uff1a\u4f7f\u7528<code>np.mean(array, axis=1)<\/code>\u6309\u884c\u8ba1\u7b97\u5e73\u5747\u503c\u3002<\/li>\n<li><strong>\u6309\u5217\u8ba1\u7b97\u5e73\u5747\u503c<\/strong>\uff1a\u4f7f\u7528<code>np.mean(array, axis=0)<\/code>\u6309\u5217\u8ba1\u7b97\u5e73\u5747\u503c\u3002<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u6027\u80fd\u4f18\u5316<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u6570\u7ec4\uff0c\u6027\u80fd\u4f18\u5316\u662f\u5fc5\u987b\u8003\u8651\u7684\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316\u6280\u5de7\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528NumPy<\/strong>\uff1a\u5c3d\u91cf\u4f7f\u7528NumPy\u5e93\uff0c\u56e0\u4e3a\u5b83\u5e95\u5c42\u4f7f\u7528C\u8bed\u8a00\u5b9e\u73b0\uff0c\u8ba1\u7b97\u901f\u5ea6\u975e\u5e38\u5feb\u3002<\/li>\n<li><strong>\u907f\u514d\u91cd\u590d\u8ba1\u7b97<\/strong>\uff1a\u5728\u5faa\u73af\u4e2d\u907f\u514d\u91cd\u590d\u8ba1\u7b97\uff0c\u5c3d\u91cf\u5c06\u8ba1\u7b97\u63d0\u524d\u3002<\/li>\n<li><strong>\u4f7f\u7528\u5e76\u884c\u8ba1\u7b97<\/strong>\uff1a\u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u6570\u636e\u96c6\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5e76\u884c\u8ba1\u7b97\u5e93\uff0c\u5982Dask\u3002<\/li>\n<\/ol>\n<p><p>\u516b\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u8bb2\u89e3\u4e86\u591a\u79cd\u8ba1\u7b97\u6570\u7ec4\u5e73\u5747\u503c\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001for\u5faa\u73af\u3001NumPy\u5e93\u3001Pandas\u5e93\u7b49\uff0c\u5e76\u63a2\u8ba8\u4e86\u6570\u636e\u6e05\u6d17\u548c\u9884\u5904\u7406\u3001\u591a\u7ef4\u6570\u7ec4\u5904\u7406\u3001\u6027\u80fd\u4f18\u5316\u7b49\u76f8\u5173\u95ee\u9898\u3002<strong>\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5<\/strong>\uff0c\u53ef\u4ee5\u8ba9\u4f60\u7684\u4ee3\u7801\u66f4\u9ad8\u6548\u3001\u66f4\u7b80\u6d01\u3001\u66f4\u6613\u7ef4\u62a4\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u4f60\u5728\u5b9e\u9645\u5de5\u4f5c\u4e2d\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8ba1\u7b97\u5217\u8868\u7684\u5e73\u5747\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u8ba1\u7b97\u5217\u8868\u7684\u5e73\u5747\u503c\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u51fd\u6570\u548c\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\u6765\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>sum()<\/code>\u51fd\u6570\u8ba1\u7b97\u5217\u8868\u4e2d\u6240\u6709\u5143\u7d20\u7684\u603b\u548c\uff0c\u7136\u540e\u5c06\u5176\u9664\u4ee5\u5217\u8868\u7684\u957f\u5ea6\uff0c\u4f7f\u7528<code>len()<\/code>\u51fd\u6570\u83b7\u53d6\u5143\u7d20\u6570\u91cf\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5217\u8868<code>numbers = [1, 2, 3, 4, 5]<\/code>\uff0c\u90a3\u4e48\u5e73\u5747\u503c\u7684\u8ba1\u7b97\u65b9\u5f0f\u4e3a<code>average = sum(numbers) \/ len(numbers)<\/code>\u3002\u8fd9\u6837\u53ef\u4ee5\u8f7b\u677e\u5f97\u5230\u5e73\u5747\u503c\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u5e93\u53ef\u4ee5\u7b80\u5316Python\u4e2d\u6570\u7ec4\u5e73\u5747\u503c\u7684\u8ba1\u7b97\uff1f<\/strong><br \/>\u786e\u5b9e\u5b58\u5728\u4e00\u4e9b\u5e93\u53ef\u4ee5\u7b80\u5316\u8ba1\u7b97\u3002NumPy\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u5e93\uff0c\u4e13\u95e8\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u3002\u4f7f\u7528NumPy\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>numpy.mean()<\/code>\u51fd\u6570\u8f7b\u677e\u8ba1\u7b97\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002\u53ea\u9700\u5c06\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u8be5\u51fd\u6570\uff0c\u4f8b\u5982\uff1a<code>import numpy as np; average = np.mean(numbers)<\/code>\u3002\u8fd9\u6837\u4e0d\u4ec5\u7b80\u5316\u4e86\u4ee3\u7801\uff0c\u8fd8\u63d0\u9ad8\u4e86\u8ba1\u7b97\u6548\u7387\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u5305\u542b\u975e\u6570\u5b57\u5143\u7d20\u7684\u6570\u7ec4\u4ee5\u8ba1\u7b97\u5e73\u5747\u503c\uff1f<\/strong><br \/>\u5728\u5904\u7406\u5305\u542b\u975e\u6570\u5b57\u5143\u7d20\u7684\u6570\u7ec4\u65f6\uff0c\u60a8\u9700\u8981\u5148\u7b5b\u9009\u51fa\u6709\u6548\u7684\u6570\u5b57\u3002\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u8fc7\u6ee4\u51fa\u6570\u5b57\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u6570\u7ec4<code>data = [1, &#39;a&#39;, 3, None, 5]<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7<code>numbers = [x for x in data if isinstance(x, (int, float))]<\/code>\u6765\u83b7\u53d6\u6709\u6548\u6570\u5b57\uff0c\u7136\u540e\u518d\u8fdb\u884c\u5e73\u5747\u503c\u8ba1\u7b97\uff0c<code>average = sum(numbers) \/ len(numbers)<\/code>\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u8ba1\u7b97\u7684\u51c6\u786e\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u6c42\u6570\u7ec4\u5e73\u5747\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u901a\u8fc7\u5faa\u73af\u8ba1\u7b97\u3001\u4f7f\u7528NumPy\u5e93\u7b49\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06 [&hellip;]","protected":false},"author":3,"featured_media":1036744,"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\/1036734"}],"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=1036734"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1036734\/revisions"}],"predecessor-version":[{"id":1036749,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1036734\/revisions\/1036749"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1036744"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1036734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1036734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1036734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}