{"id":1053702,"date":"2024-12-31T14:36:09","date_gmt":"2024-12-31T06:36:09","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1053702.html"},"modified":"2024-12-31T14:36:11","modified_gmt":"2024-12-31T06:36:11","slug":"python%e5%a6%82%e4%bd%95%e6%b1%82%e5%88%97%e8%a1%a8%e4%b8%ad%e7%9a%84%e4%b8%ad%e4%bd%8d%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1053702.html","title":{"rendered":"python\u5982\u4f55\u6c42\u5217\u8868\u4e2d\u7684\u4e2d\u4f4d\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/0583fdcd-1c2e-4ce6-8777-57031cc743ff.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u6c42\u5217\u8868\u4e2d\u7684\u4e2d\u4f4d\u6570\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u6c42\u5217\u8868\u4e2d\u7684\u4e2d\u4f4d\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u6392\u5e8f\u3001\u5947\u5076\u5224\u65ad\u3001\u7edf\u8ba1\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u7b49\u65b9\u6cd5<\/strong>\u3002\u5728\u8ba1\u7b97\u5217\u8868\u4e2d\u4f4d\u6570\u65f6\uff0c\u9700\u8981\u5c06\u5217\u8868\u6392\u5e8f\uff0c\u7136\u540e\u6839\u636e\u5217\u8868\u7684\u957f\u5ea6\u5224\u65ad\u662f\u5947\u6570\u8fd8\u662f\u5076\u6570\u3002\u5982\u679c\u5217\u8868\u957f\u5ea6\u662f\u5947\u6570\uff0c\u5219\u4e2d\u4f4d\u6570\u662f\u6392\u5e8f\u540e\u4e2d\u95f4\u4f4d\u7f6e\u7684\u5143\u7d20\uff1b\u5982\u679c\u662f\u5076\u6570\uff0c\u5219\u4e2d\u4f4d\u6570\u662f\u6392\u5e8f\u540e\u4e2d\u95f4\u4e24\u4e2a\u5143\u7d20\u7684\u5e73\u5747\u503c\u3002<strong>\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>statistics<\/code>\u6a21\u5757\u6765\u7b80\u5316\u4e2d\u4f4d\u6570\u7684\u8ba1\u7b97<\/strong>\uff0c\u8be5\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e2a\u76f4\u63a5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u7684\u51fd\u6570\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u76f4\u63a5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u7684\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528Python\u8ba1\u7b97\u5217\u8868\u7684\u4e2d\u4f4d\u6570\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u51e0\u4e2a\u6b65\u9aa4\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>statistics<\/code>\u6a21\u5757\uff0c\u6216\u8005\u624b\u52a8\u5b9e\u73b0\u4e2d\u4f4d\u6570\u8ba1\u7b97\u3002\u4e0b\u9762\u4ecb\u7ecd\u8fd9\u4e24\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>statistics<\/code>\u6a21\u5757<\/h4>\n<\/p>\n<p><p><code>statistics<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3a<code>median<\/code>\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import statistics<\/p>\n<p>data = [2, 3, 5, 1, 4]<\/p>\n<p>median = statistics.median(data)<\/p>\n<p>print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165<code>statistics<\/code>\u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e00\u4e9b\u6570\u5b57\u7684\u5217\u8868<code>data<\/code>\uff0c\u5e76\u4f7f\u7528<code>median<\/code>\u51fd\u6570\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002\u6700\u540e\uff0c\u6253\u5370\u4e2d\u4f4d\u6570\u7684\u503c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u624b\u52a8\u8ba1\u7b97\u4e2d\u4f4d\u6570<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4e0d\u60f3\u4f7f\u7528<code>statistics<\/code>\u6a21\u5757\uff0c\u4e5f\u53ef\u4ee5\u624b\u52a8\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [2, 3, 5, 1, 4]<\/p>\n<p>data.sort()<\/p>\n<p>length = len(data)<\/p>\n<p>if length % 2 == 0:<\/p>\n<p>    median = (data[length \/\/ 2 - 1] + data[length \/\/ 2]) \/ 2<\/p>\n<p>else:<\/p>\n<p>    median = data[length \/\/ 2]<\/p>\n<p>print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u6839\u636e\u5217\u8868\u7684\u957f\u5ea6\u5224\u65ad\u662f\u5947\u6570\u8fd8\u662f\u5076\u6570\u3002\u5982\u679c\u662f\u5076\u6570\uff0c\u8ba1\u7b97\u4e2d\u95f4\u4e24\u4e2a\u5143\u7d20\u7684\u5e73\u5747\u503c\uff1b\u5982\u679c\u662f\u5947\u6570\uff0c\u5219\u76f4\u63a5\u53d6\u4e2d\u95f4\u4f4d\u7f6e\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5904\u7406\u542b\u6709\u91cd\u590d\u5143\u7d20\u7684\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u5217\u8868\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002\u91cd\u590d\u5143\u7d20\u4e0d\u4f1a\u5f71\u54cd\u4e2d\u4f4d\u6570\u7684\u8ba1\u7b97\uff0c\u56e0\u4e3a\u4e2d\u4f4d\u6570\u53ea\u53d6\u51b3\u4e8e\u6392\u5e8f\u540e\u7684\u4f4d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u5305\u542b\u91cd\u590d\u5143\u7d20\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [2, 3, 5, 1, 4, 3, 2]<\/p>\n<p>data.sort()<\/p>\n<p>length = len(data)<\/p>\n<p>if length % 2 == 0:<\/p>\n<p>    median = (data[length \/\/ 2 - 1] + data[length \/\/ 2]) \/ 2<\/p>\n<p>else:<\/p>\n<p>    median = data[length \/\/ 2]<\/p>\n<p>print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868<code>data<\/code>\u5305\u542b\u4e00\u4e9b\u91cd\u590d\u5143\u7d20\u3002\u6211\u4eec\u5148\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u6309\u524d\u9762\u4ecb\u7ecd\u7684\u65b9\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5904\u7406\u542b\u6709\u5b57\u7b26\u4e32\u6216\u6df7\u5408\u7c7b\u578b\u7684\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5217\u8868\u4e2d\u5305\u542b\u5b57\u7b26\u4e32\u6216\u5176\u4ed6\u975e\u6570\u5b57\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u8ba1\u7b97\u4e2d\u4f4d\u6570\u65f6\u4f1a\u9047\u5230\u95ee\u9898\u3002\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5217\u8868\u4e2d\u53ea\u5305\u542b\u6570\u5b57\u7c7b\u578b\u7684\u5143\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u6df7\u5408\u7c7b\u578b\u5143\u7d20\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [2, 3, 5, &quot;a&quot;, 1, 4, &quot;b&quot;]<\/p>\n<h2><strong>\u8fc7\u6ee4\u6389\u975e\u6570\u5b57\u7c7b\u578b\u7684\u5143\u7d20<\/strong><\/h2>\n<p>filtered_data = [x for x in data if isinstance(x, (int, float))]<\/p>\n<p>filtered_data.sort()<\/p>\n<p>length = len(filtered_data)<\/p>\n<p>if length % 2 == 0:<\/p>\n<p>    median = (filtered_data[length \/\/ 2 - 1] + filtered_data[length \/\/ 2]) \/ 2<\/p>\n<p>else:<\/p>\n<p>    median = filtered_data[length \/\/ 2]<\/p>\n<p>print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868<code>data<\/code>\u5305\u542b\u5b57\u7b26\u4e32\u5143\u7d20\u3002\u6211\u4eec\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u8fc7\u6ee4\u6389\u975e\u6570\u5b57\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u7136\u540e\u6309\u524d\u9762\u4ecb\u7ecd\u7684\u65b9\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u7a7a\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff0c\u8ba1\u7b97\u4e2d\u4f4d\u6570\u65f6\u4f1a\u9047\u5230\u95ee\u9898\u3002\u6211\u4eec\u9700\u8981\u5728\u8ba1\u7b97\u4e4b\u524d\u68c0\u67e5\u5217\u8868\u662f\u5426\u4e3a\u7a7a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u7a7a\u5217\u8868\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = []<\/p>\n<p>if len(data) == 0:<\/p>\n<p>    print(&quot;The list is empty.&quot;)<\/p>\n<p>else:<\/p>\n<p>    data.sort()<\/p>\n<p>    length = len(data)<\/p>\n<p>    if length % 2 == 0:<\/p>\n<p>        median = (data[length \/\/ 2 - 1] + data[length \/\/ 2]) \/ 2<\/p>\n<p>    else:<\/p>\n<p>        median = data[length \/\/ 2]<\/p>\n<p>    print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u68c0\u67e5\u5217\u8868\u662f\u5426\u4e3a\u7a7a\u3002\u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff0c\u6253\u5370\u63d0\u793a\u4fe1\u606f\uff1b\u5426\u5219\uff0c\u6309\u524d\u9762\u4ecb\u7ecd\u7684\u65b9\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5904\u7406\u542b\u6709\u6d6e\u70b9\u6570\u7684\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u5217\u8868\u4e2d\u53ef\u80fd\u5305\u542b\u6d6e\u70b9\u6570\u3002\u6d6e\u70b9\u6570\u4e0d\u4f1a\u5f71\u54cd\u4e2d\u4f4d\u6570\u7684\u8ba1\u7b97\uff0c\u56e0\u4e3a\u4e2d\u4f4d\u6570\u53ea\u53d6\u51b3\u4e8e\u6392\u5e8f\u540e\u7684\u4f4d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u5305\u542b\u6d6e\u70b9\u6570\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [2.3, 3.1, 5.7, 1.4, 4.8]<\/p>\n<p>data.sort()<\/p>\n<p>length = len(data)<\/p>\n<p>if length % 2 == 0:<\/p>\n<p>    median = (data[length \/\/ 2 - 1] + data[length \/\/ 2]) \/ 2<\/p>\n<p>else:<\/p>\n<p>    median = data[length \/\/ 2]<\/p>\n<p>print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868<code>data<\/code>\u5305\u542b\u4e00\u4e9b\u6d6e\u70b9\u6570\u3002\u6211\u4eec\u5148\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u6309\u524d\u9762\u4ecb\u7ecd\u7684\u65b9\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u8ba1\u7b97\u5d4c\u5957\u5217\u8868\u7684\u4e2d\u4f4d\u6570<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5217\u8868\u662f\u5d4c\u5957\u7684\uff08\u5373\u5305\u542b\u5b50\u5217\u8868\uff09\uff0c\u8ba1\u7b97\u4e2d\u4f4d\u6570\u65f6\u9700\u8981\u5c06\u6240\u6709\u5b50\u5217\u8868\u5c55\u5f00\u4e3a\u4e00\u4e2a\u5e73\u9762\u5217\u8868\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u5d4c\u5957\u5217\u8868\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import itertools<\/p>\n<p>data = [[2, 3], [5, 1], [4]]<\/p>\n<p>flattened_data = list(itertools.ch<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.from_iterable(data))<\/p>\n<p>flattened_data.sort()<\/p>\n<p>length = len(flattened_data)<\/p>\n<p>if length % 2 == 0:<\/p>\n<p>    median = (flattened_data[length \/\/ 2 - 1] + flattened_data[length \/\/ 2]) \/ 2<\/p>\n<p>else:<\/p>\n<p>    median = flattened_data[length \/\/ 2]<\/p>\n<p>print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868<code>data<\/code>\u662f\u5d4c\u5957\u7684\u3002\u6211\u4eec\u4f7f\u7528<code>itertools.chain.from_iterable<\/code>\u51fd\u6570\u5c06\u6240\u6709\u5b50\u5217\u8868\u5c55\u5f00\u4e3a\u4e00\u4e2a\u5e73\u9762\u5217\u8868\uff0c\u7136\u540e\u6309\u524d\u9762\u4ecb\u7ecd\u7684\u65b9\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u8ba1\u7b97\u5927\u578b\u6570\u636e\u96c6\u7684\u4e2d\u4f4d\u6570<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u8ba1\u7b97\u4e2d\u4f4d\u6570\u53ef\u80fd\u9700\u8981\u66f4\u591a\u7684\u5185\u5b58\u548c\u65f6\u95f4\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5206\u5757\u5904\u7406\u7684\u65b9\u6cd5\u6765\u8282\u7701\u5185\u5b58\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a\u5927\u578b\u6570\u636e\u96c6<\/strong><\/h2>\n<p>data = [random.randint(1, 1000000) for _ in range(1000000)]<\/p>\n<p>def find_median(data):<\/p>\n<p>    data.sort()<\/p>\n<p>    length = len(data)<\/p>\n<p>    if length % 2 == 0:<\/p>\n<p>        median = (data[length \/\/ 2 - 1] + data[length \/\/ 2]) \/ 2<\/p>\n<p>    else:<\/p>\n<p>        median = data[length \/\/ 2]<\/p>\n<p>    return median<\/p>\n<p>median = find_median(data)<\/p>\n<p>print(f&quot;The median is: {median}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e00\u4e2a\u5305\u542b\u4e00\u767e\u4e07\u4e2a\u968f\u673a\u6574\u6570\u7684\u5927\u578b\u6570\u636e\u96c6\u3002\u7136\u540e\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<code>find_median<\/code>\uff0c\u6309\u524d\u9762\u4ecb\u7ecd\u7684\u65b9\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u8ba1\u7b97\u5217\u8868\u4e2d\u7684\u4e2d\u4f4d\u6570\u3002\u65e0\u8bba\u662f\u4f7f\u7528\u5185\u7f6e\u7684<code>statistics<\/code>\u6a21\u5757\uff0c\u8fd8\u662f\u624b\u52a8\u5b9e\u73b0\u4e2d\u4f4d\u6570\u8ba1\u7b97\uff0c\u6216\u8005\u5904\u7406\u5305\u542b\u91cd\u590d\u5143\u7d20\u3001\u5b57\u7b26\u4e32\u3001\u6df7\u5408\u7c7b\u578b\u3001\u6d6e\u70b9\u6570\u3001\u5d4c\u5957\u5217\u8868\u4ee5\u53ca\u5927\u578b\u6570\u636e\u96c6\u7684\u60c5\u51b5\uff0c\u90fd\u80fd\u591f\u5f97\u51fa\u6b63\u786e\u7684\u4e2d\u4f4d\u6570\u3002\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u5404\u79cd\u573a\u666f\u4e0b\u7075\u6d3b\u5730\u8ba1\u7b97\u4e2d\u4f4d\u6570\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\u4e2d\u4f4d\u6570\uff1f<\/strong><br \/>\u8ba1\u7b97\u4e2d\u4f4d\u6570\u7684\u5e38\u7528\u65b9\u6cd5\u662f\u9996\u5148\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u6839\u636e\u5217\u8868\u7684\u957f\u5ea6\u786e\u5b9a\u4e2d\u4f4d\u6570\u7684\u4f4d\u7f6e\u3002\u5982\u679c\u5217\u8868\u957f\u5ea6\u4e3a\u5947\u6570\uff0c\u5219\u4e2d\u4f4d\u6570\u4e3a\u4e2d\u95f4\u5143\u7d20\uff1b\u5982\u679c\u4e3a\u5076\u6570\uff0c\u5219\u4e2d\u4f4d\u6570\u4e3a\u4e2d\u95f4\u4e24\u4e2a\u5143\u7d20\u7684\u5e73\u5747\u503c\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5185\u7f6e<code>sorted()<\/code>\u51fd\u6570\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u5229\u7528\u7d22\u5f15\u6765\u83b7\u53d6\u4e2d\u4f4d\u6570\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u5e93\u8ba1\u7b97\u4e2d\u4f4d\u6570\u662f\u5426\u66f4\u65b9\u4fbf\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u4f7f\u7528NumPy\u5e93\u53ef\u4ee5\u66f4\u7b80\u5355\u5730\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002NumPy\u63d0\u4f9b\u4e86<code>numpy.median()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u76f4\u63a5\u5bf9\u5217\u8868\u6216\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd4\u56de\u4e2d\u4f4d\u6570\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4ec5\u7b80\u6d01\uff0c\u800c\u4e14\u5728\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\u66f4\u9ad8\u6548\u3002<\/p>\n<p><strong>\u5982\u679c\u5217\u8868\u4e3a\u7a7a\u6216\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u5982\u4f55\u5904\u7406\uff1f<\/strong><br \/>\u5728\u8ba1\u7b97\u4e2d\u4f4d\u6570\u4e4b\u524d\uff0c\u53ef\u4ee5\u5148\u68c0\u67e5\u5217\u8868\u7684\u957f\u5ea6\u3002\u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff0c\u6700\u597d\u8fd4\u56de\u4e00\u4e2a\u8bf4\u660e\u6027\u7684\u4fe1\u606f\uff0c\u5982\u201c\u5217\u8868\u4e3a\u7a7a\uff0c\u65e0\u6cd5\u8ba1\u7b97\u4e2d\u4f4d\u6570\u201d\u3002\u5982\u679c\u5217\u8868\u4e2d\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u5219\u8be5\u5143\u7d20\u5373\u4e3a\u4e2d\u4f4d\u6570\u3002\u52a1\u5fc5\u5728\u5b9e\u73b0\u4ee3\u7801\u65f6\u6dfb\u52a0\u8fd9\u4e9b\u8fb9\u754c\u6761\u4ef6\u7684\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u6c42\u5217\u8868\u4e2d\u7684\u4e2d\u4f4d\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u6392\u5e8f\u3001\u5947\u5076\u5224\u65ad\u3001\u7edf\u8ba1\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u7b49\u65b9\u6cd5\u3002\u5728\u8ba1\u7b97\u5217\u8868\u4e2d\u4f4d\u6570\u65f6\uff0c\u9700\u8981\u5c06 [&hellip;]","protected":false},"author":3,"featured_media":1053720,"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\/1053702"}],"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=1053702"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1053702\/revisions"}],"predecessor-version":[{"id":1053722,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1053702\/revisions\/1053722"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1053720"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1053702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1053702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1053702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}