{"id":1145553,"date":"2025-01-08T23:09:10","date_gmt":"2025-01-08T15:09:10","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1145553.html"},"modified":"2025-01-08T23:09:13","modified_gmt":"2025-01-08T15:09:13","slug":"python%e5%a6%82%e4%bd%95%e5%90%91%e4%b8%80%e4%b8%aa%e4%ba%8c%e7%bb%b4%e7%a9%ba%e6%95%b0%e7%bb%84%e5%ad%98%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1145553.html","title":{"rendered":"python\u5982\u4f55\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24182052\/c642c5e8-ea33-4d26-bcd9-e504db71e1bc.webp\" alt=\"python\u5982\u4f55\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u51e0\u79cd\uff1a<strong>\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u3001NumPy\u6570\u7ec4\u3001Pandas DataFrame<\/strong>\u3002\u5176\u4e2d\uff0cNumPy\u6570\u7ec4\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u503c\u8fd0\u7b97\u529f\u80fd\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u51e0\u79cd\u65b9\u6cd5\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5d4c\u5957\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u5d4c\u5957\u5217\u8868\u662fPython\u5185\u7f6e\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u8868\u793a\u4e8c\u7ef4\u6570\u7ec4\u3002\u6211\u4eec\u53ef\u4ee5\u5148\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u5d4c\u5957\u5217\u8868\uff0c\u7136\u540e\u9010\u4e2a\u5411\u91cc\u9762\u6dfb\u52a0\u6570\u503c\u3002<\/p>\n<\/p>\n<p><h4>\u521b\u5efa\u548c\u521d\u59cb\u5316\u5d4c\u5957\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u5d4c\u5957\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array = [[]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e3a\u4e86\u5411\u8fd9\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u6dfb\u52a0\u6570\u503c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">rows, cols = 3, 3  # \u5047\u8bbe\u6211\u4eec\u9700\u8981\u4e00\u4e2a3x3\u7684\u6570\u7ec4<\/p>\n<p>array = [[0]*cols for _ in range(rows)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2a3&#215;3\u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u5e76\u521d\u59cb\u5316\u4e3a\u5168\u96f6\u3002<\/p>\n<\/p>\n<p><h4>\u6dfb\u52a0\u6570\u503c<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u6765\u4fee\u6539\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u6570\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array[0][0] = 1<\/p>\n<p>array[1][1] = 2<\/p>\n<p>array[2][2] = 3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u6210\u529f\u5730\u5411\u5d4c\u5957\u5217\u8868\u4e2d\u6dfb\u52a0\u4e86\u6570\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528NumPy\u6570\u7ec4<\/h3>\n<\/p>\n<p><p>NumPy\u662fPython\u7684\u4e00\u4e2a\u5e93\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u503c\u8fd0\u7b97\u529f\u80fd\u3002\u4f7f\u7528NumPy\u6570\u7ec4\u53ef\u4ee5\u66f4\u52a0\u9ad8\u6548\u5730\u64cd\u4f5c\u4e8c\u7ef4\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5NumPy<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5NumPy\uff0c\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><h4>\u521b\u5efa\u548c\u521d\u59cb\u5316NumPy\u6570\u7ec4<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528<code>numpy.zeros<\/code>\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>rows, cols = 3, 3  # \u5047\u8bbe\u6211\u4eec\u9700\u8981\u4e00\u4e2a3x3\u7684\u6570\u7ec4<\/p>\n<p>array = np.zeros((rows, cols))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6dfb\u52a0\u6570\u503c<\/h4>\n<\/p>\n<p><p>\u5411NumPy\u6570\u7ec4\u6dfb\u52a0\u6570\u503c\u7684\u65b9\u6cd5\u4e0e\u5d4c\u5957\u5217\u8868\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u6765\u4fee\u6539\u6570\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array[0, 0] = 1<\/p>\n<p>array[1, 1] = 2<\/p>\n<p>array[2, 2] = 3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>NumPy\u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u9ad8\u6548\u7684\u65b9\u6cd5\u6765\u4fee\u6539\u6570\u7ec4\uff0c\u5982\u5207\u7247\u64cd\u4f5c\u3001\u5e03\u5c14\u7d22\u5f15\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Pandas DataFrame<\/h3>\n<\/p>\n<p><p>Pandas\u662f\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684Python\u5e93\uff0c\u4e3b\u8981\u7528\u4e8e\u6570\u636e\u5206\u6790\u3002Pandas\u7684DataFrame\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u5e26\u6807\u7b7e\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5Pandas<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5Pandas\uff0c\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 pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u521b\u5efa\u548c\u521d\u59cb\u5316DataFrame<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>DataFrame<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u4e8c\u7ef4\u6570\u7ec4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>rows, cols = 3, 3  # \u5047\u8bbe\u6211\u4eec\u9700\u8981\u4e00\u4e2a3x3\u7684\u6570\u7ec4<\/p>\n<p>array = pd.DataFrame(np.zeros((rows, cols)))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6dfb\u52a0\u6570\u503c<\/h4>\n<\/p>\n<p><p>\u5411DataFrame\u6dfb\u52a0\u6570\u503c\u7684\u65b9\u6cd5\u4e0e\u524d\u9762\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u6765\u4fee\u6539\u6570\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array.iloc[0, 0] = 1<\/p>\n<p>array.iloc[1, 1] = 2<\/p>\n<p>array.iloc[2, 2] = 3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Pandas\u8fd8\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5982\u5bf9\u6570\u636e\u8fdb\u884c\u8fc7\u6ee4\u3001\u5206\u7ec4\u3001\u805a\u5408\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5176\u4ed6\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4ee5\u4e0a\u4e09\u79cd\u65b9\u6cd5\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u65b9\u6cd5\u53ef\u4ee5\u5411\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684\u6807\u51c6\u5e93<code>array<\/code>\uff0c\u4e0d\u8fc7\u5b83\u4e0d\u652f\u6301\u591a\u7ef4\u6570\u7ec4\uff0c\u56e0\u6b64\u9700\u8981\u81ea\u5df1\u5b9e\u73b0\u591a\u7ef4\u6570\u7ec4\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u6807\u51c6\u5e93array<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import array<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>rows, cols = 3, 3<\/p>\n<p>array_2d = [array.array(&#39;i&#39;, [0]*cols) for _ in range(rows)]<\/p>\n<h2><strong>\u6dfb\u52a0\u6570\u503c<\/strong><\/h2>\n<p>array_2d[0][0] = 1<\/p>\n<p>array_2d[1][1] = 2<\/p>\n<p>array_2d[2][2] = 3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u7f3a\u70b9\u662f\u64cd\u4f5c\u4e0d\u591f\u7075\u6d3b\uff0c\u800c\u4e14\u6548\u7387\u8f83\u4f4e\u3002<\/p>\n<\/p>\n<p><h3>\u8be6\u7ec6\u63cf\u8ff0NumPy\u7684\u4f7f\u7528<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3NumPy\u6570\u7ec4\u7684\u64cd\u4f5c\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63cf\u8ff0\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><h4>\u521d\u59cb\u5316\u6570\u7ec4<\/h4>\n<\/p>\n<p><p>\u9664\u4e86<code>numpy.zeros<\/code>\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u6765\u521d\u59cb\u5316\u6570\u7ec4\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>numpy.ones<\/code>\uff1a\u521b\u5efa\u51681\u6570\u7ec4<\/li>\n<li><code>numpy.empty<\/code>\uff1a\u521b\u5efa\u672a\u521d\u59cb\u5316\u7684\u6570\u7ec4<\/li>\n<li><code>numpy.full<\/code>\uff1a\u521b\u5efa\u6307\u5b9a\u503c\u7684\u6570\u7ec4<\/li>\n<li><code>numpy.eye<\/code>\uff1a\u521b\u5efa\u5bf9\u89d2\u7ebf\u4e3a1\u7684\u6570\u7ec4<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">array_ones = np.ones((rows, cols))<\/p>\n<p>array_empty = np.empty((rows, cols))<\/p>\n<p>array_full = np.full((rows, cols), 7)<\/p>\n<p>array_eye = np.eye(rows)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6570\u7ec4\u8fd0\u7b97<\/h4>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u7ec4\u8fd0\u7b97\u529f\u80fd\uff0c\u5982\u52a0\u51cf\u4e58\u9664\u3001\u77e9\u9635\u4e58\u6cd5\u3001\u8f6c\u7f6e\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array_a = np.array([[1, 2], [3, 4]])<\/p>\n<p>array_b = np.array([[5, 6], [7, 8]])<\/p>\n<h2><strong>\u52a0\u51cf\u4e58\u9664<\/strong><\/h2>\n<p>sum_array = array_a + array_b<\/p>\n<p>diff_array = array_a - array_b<\/p>\n<p>prod_array = array_a * array_b<\/p>\n<p>quot_array = array_a \/ array_b<\/p>\n<h2><strong>\u77e9\u9635\u4e58\u6cd5<\/strong><\/h2>\n<p>matmul_array = np.matmul(array_a, array_b)<\/p>\n<h2><strong>\u8f6c\u7f6e<\/strong><\/h2>\n<p>transpose_array = np.transpose(array_a)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u9ad8\u7ea7\u7d22\u5f15\u548c\u5207\u7247<\/h4>\n<\/p>\n<p><p>NumPy\u652f\u6301\u9ad8\u7ea7\u7d22\u5f15\u548c\u5207\u7247\u64cd\u4f5c\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u9009\u62e9\u3001\u4fee\u6539\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u7b2c\u4e8c\u884c<\/p>\n<p>second_row = array_a[1, :]<\/p>\n<h2><strong>\u9009\u62e9\u7b2c\u4e8c\u5217<\/strong><\/h2>\n<p>second_column = array_a[:, 1]<\/p>\n<h2><strong>\u9009\u62e9\u5b50\u6570\u7ec4<\/strong><\/h2>\n<p>sub_array = array_a[0:2, 0:2]<\/p>\n<h2><strong>\u5e03\u5c14\u7d22\u5f15<\/strong><\/h2>\n<p>bool_index = array_a &gt; 2<\/p>\n<p>filtered_array = array_a[bool_index]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e9b\u9ad8\u7ea7\u64cd\u4f5c\u4f7f\u5f97NumPy\u5728\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u65f6\u975e\u5e38\u9ad8\u6548\u548c\u7075\u6d3b\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a<strong>\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u3001NumPy\u6570\u7ec4\u3001Pandas DataFrame<\/strong>\u3002\u5176\u4e2d\uff0cNumPy\u6570\u7ec4\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u503c\u8fd0\u7b97\u529f\u80fd\u3002\u5d4c\u5957\u5217\u8868\u548cPandas DataFrame\u4e5f\u5404\u6709\u4f18\u70b9\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u5e0c\u671b\u672c\u6587\u8be6\u7ec6\u7684\u4ecb\u7ecd\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\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\u4e8c\u7ef4\u7a7a\u6570\u7ec4\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u6765\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u521b\u5efa\u4e00\u4e2a\u6307\u5b9a\u5927\u5c0f\u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6240\u6709\u5143\u7d20\u521d\u59cb\u4e3a\u96f6\u6216\u5176\u4ed6\u9ed8\u8ba4\u503c\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">rows, cols = 3, 4  # \u6307\u5b9a\u884c\u6570\u548c\u5217\u6570\narray_2d = [[0 for _ in range(cols)] for _ in range(rows)]\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2a3\u884c4\u5217\u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6240\u6709\u5143\u7d20\u521d\u59cb\u5316\u4e3a0\u3002<\/p>\n<p><strong>\u5982\u4f55\u5411\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u6dfb\u52a0\u6570\u636e\uff1f<\/strong><br \/>\u5411\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u6dfb\u52a0\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u8bbf\u95ee\u7279\u5b9a\u7d22\u5f15\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u5728\u7b2c1\u884c\u7b2c2\u5217\u7684\u4f4d\u7f6e\u5b58\u5165\u6570\u5b575\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a  <\/p>\n<pre><code class=\"language-python\">array_2d[0][1] = 5  # \u6ce8\u610f\u7d22\u5f15\u4ece0\u5f00\u59cb\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u5141\u8bb8\u4f60\u5728\u6570\u7ec4\u7684\u4efb\u4f55\u4f4d\u7f6e\u63d2\u5165\u6570\u636e\uff0c\u53ea\u9700\u786e\u4fdd\u7d22\u5f15\u5728\u6570\u7ec4\u7684\u8303\u56f4\u5185\u5373\u53ef\u3002<\/p>\n<p><strong>\u5982\u4f55\u904d\u5386\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\uff1f<\/strong><br \/>\u904d\u5386\u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957\u7684for\u5faa\u73af\u3002\u5916\u5c42\u5faa\u73af\u7528\u4e8e\u904d\u5386\u884c\uff0c\u5185\u5c42\u5faa\u73af\u7528\u4e8e\u904d\u5386\u5217\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">for row in array_2d:\n    for element in row:\n        print(element, end=&#39; &#39;)\n    print()  # \u6253\u5370\u6bcf\u884c\u540e\u6362\u884c\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u9010\u884c\u6253\u5370\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u4fbf\u4e8e\u67e5\u770b\u6570\u7ec4\u7684\u7ed3\u6784\u548c\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570 \u5728Python\u4e2d\uff0c\u5411\u4e00\u4e2a\u4e8c\u7ef4\u7a7a\u6570\u7ec4\u5b58\u6570\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u51e0\u79cd\uff1a\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u3001N [&hellip;]","protected":false},"author":3,"featured_media":1145562,"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\/1145553"}],"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=1145553"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1145553\/revisions"}],"predecessor-version":[{"id":1145566,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1145553\/revisions\/1145566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1145562"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1145553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1145553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1145553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}