{"id":1120550,"date":"2025-01-08T18:57:39","date_gmt":"2025-01-08T10:57:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1120550.html"},"modified":"2025-01-08T18:57:41","modified_gmt":"2025-01-08T10:57:41","slug":"python%e7%9f%a9%e9%98%b5%e5%a6%82%e4%bd%95%e6%8c%89%e5%88%97%e5%8f%96%e6%9c%80%e5%b0%8f%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1120550.html","title":{"rendered":"python\u77e9\u9635\u5982\u4f55\u6309\u5217\u53d6\u6700\u5c0f\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25083158\/fd840b79-281c-44c7-86ef-748061275128.webp\" alt=\"python\u77e9\u9635\u5982\u4f55\u6309\u5217\u53d6\u6700\u5c0f\u503c\" \/><\/p>\n<p><p> <strong>Python \u77e9\u9635\u5982\u4f55\u6309\u5217\u53d6\u6700\u5c0f\u503c\uff0c\u4f7f\u7528NumPy\u5e93\u3001\u4f7f\u7528min\u51fd\u6570\u3001\u904d\u5386\u77e9\u9635\u5217<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5904\u7406\u77e9\u9635\u64cd\u4f5c\u6700\u5e38\u7528\u7684\u5e93\u662fNumPy\u3002NumPy\u4e0d\u4ec5\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\uff0c\u8fd8\u5305\u542b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u6267\u884c\u5404\u79cd\u77e9\u9635\u8fd0\u7b97\u3002\u4f7f\u7528NumPy\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u6309\u5217\u53d6\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7NumPy\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff0c\u5e76\u7ed9\u51fa\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528NumPy\u5e93<\/h2>\n<\/p>\n<p><p><strong>NumPy\u5e93\u662fPython\u4e2d\u8fdb\u884c\u79d1\u5b66\u8ba1\u7b97\u7684\u57fa\u7840\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u4e30\u5bcc\u7684\u51fd\u6570\u5e93\u3002<\/strong><\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5NumPy\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528NumPy\u5e93\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u521b\u5efa\u77e9\u9635<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u3002\u5728NumPy\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>numpy.array()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u77e9\u9635\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>matrix = np.array([[3, 2, 1],<\/p>\n<p>                   [6, 5, 4],<\/p>\n<p>                   [9, 8, 7]])<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u6309\u5217\u53d6\u6700\u5c0f\u503c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528NumPy\u5e93\u4e2d\u7684<code>numpy.min()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5730\u83b7\u53d6\u77e9\u9635\u6bcf\u4e00\u5217\u7684\u6700\u5c0f\u503c\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>axis<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u6309\u884c\u6216\u6309\u5217\u8fdb\u884c\u64cd\u4f5c\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u9700\u8981\u6309\u5217\u53d6\u6700\u5c0f\u503c\uff0c\u56e0\u6b64<code>axis<\/code>\u53c2\u6570\u5e94\u8bbe\u7f6e\u4e3a0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">min_values = np.min(matrix, axis=0)<\/p>\n<p>print(min_values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528min\u51fd\u6570<\/h2>\n<\/p>\n<p><p><strong>\u9664\u4e86\u4f7f\u7528NumPy\u5e93\u4e2d\u7684<code>numpy.min()<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7Python\u5185\u7f6e\u7684<code>min()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/strong><\/p>\n<\/p>\n<p><h3>1\u3001\u904d\u5386\u77e9\u9635\u5217<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u904d\u5386\u77e9\u9635\u7684\u6bcf\u4e00\u5217\uff0c\u5e76\u4f7f\u7528<code>min()<\/code>\u51fd\u6570\u83b7\u53d6\u6bcf\u4e00\u5217\u7684\u6700\u5c0f\u503c\u3002\u53ef\u4ee5\u901a\u8fc7\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u5b9e\u73b0\u8fd9\u4e00\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [<\/p>\n<p>    [3, 2, 1],<\/p>\n<p>    [6, 5, 4],<\/p>\n<p>    [9, 8, 7]<\/p>\n<p>]<\/p>\n<p>min_values = [min(column) for column in zip(*matrix)]<\/p>\n<p>print(min_values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>zip(*matrix)<\/code>\u5c06\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u7ec4\u5408\u6210\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u7136\u540e\u901a\u8fc7\u5217\u8868\u63a8\u5bfc\u5f0f\u904d\u5386\u6bcf\u4e00\u5217\uff0c\u5e76\u4f7f\u7528<code>min()<\/code>\u51fd\u6570\u83b7\u53d6\u6bcf\u4e00\u5217\u7684\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u904d\u5386\u77e9\u9635\u5217<\/h2>\n<\/p>\n<p><p><strong>\u5982\u679c\u4e0d\u4f7f\u7528NumPy\u5e93\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u6765\u83b7\u53d6\u6700\u5c0f\u503c\u3002<\/strong><\/p>\n<\/p>\n<p><h3>1\u3001\u624b\u52a8\u904d\u5386\u77e9\u9635\u5217<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u904d\u5386\u77e9\u9635\u7684\u6bcf\u4e00\u5217\uff0c\u5e76\u9010\u5217\u6bd4\u8f83\u5143\u7d20\u6765\u83b7\u53d6\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [<\/p>\n<p>    [3, 2, 1],<\/p>\n<p>    [6, 5, 4],<\/p>\n<p>    [9, 8, 7]<\/p>\n<p>]<\/p>\n<p>min_values = []<\/p>\n<p>for col in range(len(matrix[0])):<\/p>\n<p>    min_val = matrix[0][col]<\/p>\n<p>    for row in range(1, len(matrix)):<\/p>\n<p>        if matrix[row][col] &lt; min_val:<\/p>\n<p>            min_val = matrix[row][col]<\/p>\n<p>    min_values.append(min_val)<\/p>\n<p>print(min_values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u5217\u8868<code>min_values<\/code>\u6765\u5b58\u50a8\u6bcf\u4e00\u5217\u7684\u6700\u5c0f\u503c\u3002\u7136\u540e\uff0c\u901a\u8fc7\u53cc\u91cd\u5faa\u73af\u904d\u5386\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u548c\u6bcf\u4e00\u884c\uff0c\u5e76\u9010\u5217\u6bd4\u8f83\u5143\u7d20\u83b7\u53d6\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p><strong>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Python\u4e2d\u5b9e\u73b0\u6309\u5217\u53d6\u77e9\u9635\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\u3002<\/strong><\/p>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528NumPy\u5e93<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528NumPy\u5e93\u4e2d\u7684<code>numpy.min()<\/code>\u51fd\u6570\u662f\u6700\u7b80\u4fbf\u548c\u9ad8\u6548\u7684\u65b9\u6cd5\u3002NumPy\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u51fd\u6570\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u6267\u884c\u5404\u79cd\u77e9\u9635\u8fd0\u7b97\uff0c\u975e\u5e38\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528min\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4e0d\u60f3\u4f9d\u8d56NumPy\u5e93\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7Python\u5185\u7f6e\u7684<code>min()<\/code>\u51fd\u6570\u7ed3\u5408<code>zip()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u6309\u5217\u53d6\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5c0f\u89c4\u6a21\u6570\u636e\uff0c\u4f46\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u6027\u80fd\u53ef\u80fd\u4e0d\u5982NumPy\u5e93\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u904d\u5386\u77e9\u9635\u5217<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u904d\u5386\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u6765\u83b7\u53d6\u6700\u5c0f\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u6bd4\u8f83\u7e41\u7410\uff0c\u4f46\u4e0d\u4f9d\u8d56\u4efb\u4f55\u5916\u90e8\u5e93\uff0c\u9002\u7528\u4e8e\u7b80\u5355\u7684\u77e9\u9635\u64cd\u4f5c\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u6700\u5408\u9002\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u6309\u5217\u53d6\u77e9\u9635\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u63a8\u8350\u4f7f\u7528NumPy\u5e93\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u548c\u7b80\u6d01\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u4ee5\u4fbf\u8fdb\u884c\u6309\u5217\u53d6\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u521b\u5efa\u77e9\u9635\u3002\u901a\u8fc7<code>numpy.array()<\/code>\u51fd\u6570\uff0c\u4f60\u53ef\u4ee5\u5c06\u4e00\u4e2a\u5d4c\u5957\u7684\u5217\u8868\u8f6c\u6362\u4e3a\u4e00\u4e2a\u77e9\u9635\u3002\u521b\u5efa\u5b8c\u77e9\u9635\u540e\uff0c\u53ef\u4ee5\u5229\u7528NumPy\u7684\u529f\u80fd\u8f7b\u677e\u5b9e\u73b0\u6309\u5217\u53d6\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\nmatrix = np.array([[1, 2, 3],\n                   [4, 0, 6],\n                   [7, 5, 1]])\n\nmin_values = np.min(matrix, axis=0)\nprint(min_values)  # \u8f93\u51fa\u6bcf\u5217\u7684\u6700\u5c0f\u503c\n<\/code><\/pre>\n<p><strong>\u5728\u4f7f\u7528Python\u6309\u5217\u53d6\u6700\u5c0f\u503c\u65f6\uff0c\u6709\u54ea\u4e9b\u5e38\u7528\u7684\u5e93\u548c\u65b9\u6cd5\uff1f<\/strong><br \/>\u9664\u4e86NumPy\uff0cPandas\u4e5f\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5c24\u5176\u662f\u5728\u6570\u636e\u5206\u6790\u65b9\u9762\u3002\u4f7f\u7528Pandas\u7684DataFrame\u5bf9\u8c61\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u6309\u5217\u53d6\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndf = pd.DataFrame([[1, 2, 3],\n                   [4, 0, 6],\n                   [7, 5, 1]])\n\nmin_values = df.min(axis=0)\nprint(min_values)  # \u8f93\u51fa\u6bcf\u5217\u7684\u6700\u5c0f\u503c\n<\/code><\/pre>\n<p><strong>\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u5982\u4f55\u4f18\u5316\u6309\u5217\u53d6\u6700\u5c0f\u503c\u7684\u6548\u7387\uff1f<\/strong><br \/>\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u4f7f\u7528NumPy\u7684\u5411\u91cf\u5316\u64cd\u4f5c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6548\u7387\u3002\u786e\u4fdd\u4f7f\u7528NumPy\u7684\u5185\u7f6e\u51fd\u6570\u800c\u4e0d\u662fPython\u7684\u5faa\u73af\u7ed3\u6784\uff0c\u8fd9\u6837\u53ef\u4ee5\u5145\u5206\u5229\u7528\u5e95\u5c42\u7684C\u5b9e\u73b0\u6765\u52a0\u901f\u8ba1\u7b97\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u77e9\u9635\u65f6\u4f7f\u7528\u5408\u9002\u7684\u6570\u636e\u7c7b\u578b\uff08\u5982<code>float32<\/code>\u6216<code>int32<\/code>\uff09\uff0c\u4ee5\u51cf\u5c11\u5185\u5b58\u5360\u7528\u548c\u63d0\u9ad8\u8ba1\u7b97\u901f\u5ea6\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u5347\u5904\u7406\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python \u77e9\u9635\u5982\u4f55\u6309\u5217\u53d6\u6700\u5c0f\u503c\uff0c\u4f7f\u7528NumPy\u5e93\u3001\u4f7f\u7528min\u51fd\u6570\u3001\u904d\u5386\u77e9\u9635\u5217 \u5728Python\u4e2d\uff0c\u5904\u7406\u77e9\u9635\u64cd [&hellip;]","protected":false},"author":3,"featured_media":1120553,"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\/1120550"}],"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=1120550"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120550\/revisions"}],"predecessor-version":[{"id":1120554,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120550\/revisions\/1120554"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1120553"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1120550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1120550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1120550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}