{"id":1044949,"date":"2024-12-31T13:18:58","date_gmt":"2024-12-31T05:18:58","guid":{"rendered":""},"modified":"2024-12-31T13:19:00","modified_gmt":"2024-12-31T05:19:00","slug":"%e5%a6%82%e4%bd%95%e5%8f%96array%e7%ac%ac%e4%b8%80%e5%88%97python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1044949.html","title":{"rendered":"\u5982\u4f55\u53d6array\u7b2c\u4e00\u5217python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/a81cc8a0-b40f-41e7-8696-de023cc7825f.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u53d6array\u7b2c\u4e00\u5217python\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u63d0\u53d6\u4e00\u4e2a\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528Numpy\u5e93\u6765\u5b9e\u73b0\u3002\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5207\u7247\u3001\u4f7f\u7528\u7d22\u5f15\u3001\u4ee5\u53caNumpy\u63d0\u4f9b\u7684\u4fbf\u6377\u51fd\u6570\u7b49\u3002<\/strong> \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4ee3\u7801\u793a\u4f8b\u548c\u89e3\u91ca\uff0c\u4ee5\u5e2e\u52a9\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Numpy\u5e93\u521b\u5efa\u6570\u7ec4<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5Numpy\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5bfc\u5165Numpy\u5e93\u5e76\u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u6570\u7ec4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u4e8c\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5207\u7247\u63d0\u53d6\u7b2c\u4e00\u5217<\/h3>\n<\/p>\n<p><p>Numpy\u4e2d\u7684\u5207\u7247\u529f\u80fd\u975e\u5e38\u5f3a\u5927\uff0c\u53ef\u4ee5\u901a\u8fc7\u6570\u7ec4\u7684\u7d22\u5f15\u548c\u5207\u7247\u8f7b\u677e\u63d0\u53d6\u6240\u9700\u7684\u90e8\u5206\u3002\u63d0\u53d6\u7b2c\u4e00\u5217\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">first_column = array[:, 0]<\/p>\n<p>print(first_column)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c<code>:<\/code>\u8868\u793a\u9009\u62e9\u6240\u6709\u884c\uff0c<code>0<\/code>\u8868\u793a\u9009\u62e9\u7b2c\u4e00\u5217\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7b80\u6d01\u6613\u61c2\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u7d22\u5f15\u63d0\u53d6\u7b2c\u4e00\u5217<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u5207\u7247\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u663e\u5f0f\u6307\u5b9a\u884c\u548c\u5217\u7d22\u5f15\u6765\u63d0\u53d6\u7b2c\u4e00\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">first_column = array[:, [0]]<\/p>\n<p>print(first_column)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0e\u524d\u4e00\u79cd\u65b9\u6cd5\u4e0d\u540c\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e86\u4e00\u4e2a\u5217\u8868\u6765\u6307\u5b9a\u5217\u7d22\u5f15\uff0c\u7ed3\u679c\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002\u5982\u679c\u9700\u8981\u4fdd\u6301\u4e8c\u7ef4\u7ed3\u6784\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Numpy\u51fd\u6570\u63d0\u53d6\u7b2c\u4e00\u5217<\/h3>\n<\/p>\n<p><p>Numpy\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u4fbf\u6377\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u76f4\u89c2\u5730\u8fdb\u884c\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>np.take<\/code>\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">first_column = np.take(array, 0, axis=1)<\/p>\n<p>print(first_column)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>np.take<\/code>\u51fd\u6570\u53ef\u4ee5\u4ece\u6307\u5b9a\u8f74\u4e0a\u63d0\u53d6\u5143\u7d20\uff0c\u8fd9\u91cc<code>axis=1<\/code>\u8868\u793a\u6cbf\u5217\u65b9\u5411\u64cd\u4f5c\uff0c\u63d0\u53d6\u7b2c0\u5217\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u7ec4<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e00\u7ef4\u6570\u7ec4\uff0c\u867d\u7136\u6ca1\u6709\u5217\u7684\u6982\u5ff5\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u76f4\u63a5\u8bbf\u95ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array_1d = np.array([1, 2, 3, 4, 5])<\/p>\n<p>first_element = array_1d[0]<\/p>\n<p>print(first_element)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\u7684<code>first_element<\/code>\u5373\u4e3a\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5904\u7406\u591a\u7ef4\u6570\u7ec4<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u9ad8\u7ef4\u5ea6\u7684\u6570\u7ec4\uff0c\u63d0\u53d6\u7b2c\u4e00\u5217\u7684\u65b9\u5f0f\u7c7b\u4f3c\uff0c\u53ea\u9700\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8c03\u6574\u7d22\u5f15\u5373\u53ef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array_3d = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])<\/p>\n<p>first_column_3d = array_3d[:, :, 0]<\/p>\n<p>print(first_column_3d)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>array_3d<\/code>\u662f\u4e00\u4e2a\u4e09\u7ef4\u6570\u7ec4\uff0c\u63d0\u53d6\u7b2c\u4e00\u5217\u540e\u5f97\u5230\u7684\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5e94\u7528\u573a\u666f\u53ca\u6027\u80fd\u8003\u8651<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4e2d\uff0c\u63d0\u53d6\u6570\u7ec4\u7684\u67d0\u4e00\u5217\u662f\u5e38\u89c1\u64cd\u4f5c\uff0c\u53ef\u80fd\u6d89\u53ca\u7279\u5f81\u9009\u62e9\u3001\u6570\u636e\u9884\u5904\u7406\u7b49\u3002\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u5efa\u8bae\u5728\u5927\u89c4\u6a21\u6570\u636e\u4e0a\u4f7f\u7528Numpy\u7684\u9ad8\u6548\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5b9e\u9645\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u9884\u5904\u7406<\/strong>\uff1a\u5728\u5904\u7406\u6570\u636e\u96c6\u65f6\uff0c\u5e38\u5e38\u9700\u8981\u63d0\u53d6\u67d0\u4e00\u5217\u4f5c\u4e3a\u7279\u5f81\u6216\u6807\u7b7e\u3002<\/li>\n<li><strong>\u6570\u636e\u5206\u6790<\/strong>\uff1a\u5728\u5206\u6790\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u67d0\u4e00\u5217\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u6216\u53ef\u89c6\u5316\u3002<\/li>\n<li><strong>\u673a\u5668\u5b66\u4e60<\/strong>\uff1a\u5728\u8bad\u7ec3\u6a21\u578b\u65f6\uff0c\u5e38\u5e38\u9700\u8981\u63d0\u53d6\u7279\u5b9a\u5217\u7684\u6570\u636e\u4f5c\u4e3a\u8f93\u5165\u3002<\/li>\n<\/ol>\n<p><h3>\u516b\u3001\u4ee3\u7801\u793a\u4f8b\u6c47\u603b<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u65b9\u4fbf\u53c2\u8003\uff0c\u4e0b\u9762\u662f\u4e0a\u8ff0\u65b9\u6cd5\u7684\u4ee3\u7801\u6c47\u603b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u793a\u4f8b\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<h2><strong>\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528\u5207\u7247<\/strong><\/h2>\n<p>first_column_slice = array[:, 0]<\/p>\n<p>print(&quot;Using slice:&quot;, first_column_slice)<\/p>\n<h2><strong>\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528\u7d22\u5f15<\/strong><\/h2>\n<p>first_column_index = array[:, [0]]<\/p>\n<p>print(&quot;Using index:&quot;, first_column_index)<\/p>\n<h2><strong>\u65b9\u6cd5\u4e09\uff1a\u4f7f\u7528Numpy\u51fd\u6570<\/strong><\/h2>\n<p>first_column_take = np.take(array, 0, axis=1)<\/p>\n<p>print(&quot;Using np.take:&quot;, first_column_take)<\/p>\n<h2><strong>\u5904\u7406\u4e00\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array_1d = np.array([1, 2, 3, 4, 5])<\/p>\n<p>first_element_1d = array_1d[0]<\/p>\n<p>print(&quot;1D array first element:&quot;, first_element_1d)<\/p>\n<h2><strong>\u5904\u7406\u4e09\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array_3d = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])<\/p>\n<p>first_column_3d = array_3d[:, :, 0]<\/p>\n<p>print(&quot;3D array first column:&quot;, first_column_3d)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u6e05\u695a\u5730\u770b\u5230\u5728\u4e0d\u540c\u60c5\u51b5\u4e0b\u5982\u4f55\u63d0\u53d6\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\uff0c\u5e76\u7406\u89e3\u6bcf\u79cd\u65b9\u6cd5\u7684\u9002\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\uff0c\u4f8b\u5982\u6570\u7ec4\u7ef4\u5ea6\u4e0d\u5339\u914d\u3001\u7d22\u5f15\u8d85\u51fa\u8303\u56f4\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6570\u7ec4\u7ef4\u5ea6\u4e0d\u5339\u914d<\/strong>\uff1a<\/p>\n<p>\u786e\u4fdd\u64cd\u4f5c\u7684\u6570\u7ec4\u662f\u4e8c\u7ef4\u6216\u66f4\u9ad8\u7ef4\u5ea6\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if array.ndim &lt; 2:<\/p>\n<p>    r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se ValueError(&quot;Input array must be at least 2-dimensional.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7d22\u5f15\u8d85\u51fa\u8303\u56f4<\/strong>\uff1a<\/p>\n<p>\u786e\u4fdd\u7d22\u5f15\u5728\u6570\u7ec4\u8303\u56f4\u5185\uff0c\u53ef\u4ee5\u4f7f\u7528<code>array.shape<\/code>\u68c0\u67e5\u6570\u7ec4\u7684\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if 0 &gt;= array.shape[1]:<\/p>\n<p>    raise IndexError(&quot;Column index out of range.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u7f3a\u5931\u503c<\/strong>\uff1a<\/p>\n<p>\u5728\u5b9e\u9645\u6570\u636e\u4e2d\uff0c\u53ef\u80fd\u5b58\u5728\u7f3a\u5931\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528Numpy\u7684<code>np.nan<\/code>\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array_with_nan = np.array([[1, 2, np.nan], [4, np.nan, 6], [7, 8, 9]])<\/p>\n<p>first_column_with_nan = array_with_nan[:, 0]<\/p>\n<p>print(&quot;First column with NaN:&quot;, first_column_with_nan)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u63d0\u53d6\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\u662f\u6570\u636e\u5904\u7406\u4e2d\u7684\u57fa\u672c\u64cd\u4f5c\uff0c\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u4f7f\u7528Numpy\u5e93\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u5207\u7247\u3001\u7d22\u5f15\u3001Numpy\u51fd\u6570\u7b49\u3002\u540c\u65f6\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u548c\u7ef4\u5ea6\u6570\u7ec4\u7684\u6280\u5de7\uff0c\u5e76\u63d0\u4f9b\u4e86\u4ee3\u7801\u793a\u4f8b\u548c\u89e3\u51b3\u5e38\u89c1\u95ee\u9898\u7684\u65b9\u6cd5\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u5e2e\u52a9\u8bfb\u8005\u66f4\u597d\u5730\u638c\u63e1\u5982\u4f55\u5728Python\u4e2d\u63d0\u53d6\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\uff0c\u5e76\u7075\u6d3b\u5e94\u7528\u4e8e\u5404\u79cd\u6570\u636e\u5904\u7406\u573a\u666f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u63d0\u53d6\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u8f7b\u677e\u63d0\u53d6\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\uff0c\u4f8b\u5982\uff1a<code>array[:, 0]<\/code>\u3002\u8fd9\u5c06\u8fd4\u56de\u6570\u7ec4\u4e2d\u6240\u6709\u884c\u7684\u7b2c\u4e00\u5217\u6570\u636e\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\narray = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\nfirst_column = array[:, 0]\nprint(first_column)  # \u8f93\u51fa\uff1a[1 4 7]\n<\/code><\/pre>\n<p><strong>\u80fd\u5426\u4f7f\u7528\u5217\u8868\u800c\u4e0d\u662fNumPy\u6570\u7ec4\u6765\u83b7\u53d6\u7b2c\u4e00\u5217\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\uff01\u5982\u679c\u4f60\u7684\u6570\u636e\u5b58\u50a8\u5728\u5d4c\u5957\u5217\u8868\u4e2d\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u65b9\u4fbf\u5730\u63d0\u53d6\u7b2c\u4e00\u5217\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\nfirst_column = [row[0] for row in data]\nprint(first_column)  # \u8f93\u51fa\uff1a[1, 4, 7]\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u9002\u5408\u5904\u7406\u5c0f\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<p><strong>\u63d0\u53d6\u7b2c\u4e00\u5217\u65f6\uff0c\u5982\u4f55\u5904\u7406\u4e0d\u540c\u957f\u5ea6\u7684\u5d4c\u5957\u5217\u8868\uff1f<\/strong><br \/>\u5f53\u5d4c\u5957\u5217\u8868\u7684\u6bcf\u4e00\u884c\u957f\u5ea6\u4e0d\u4e00\u81f4\u65f6\uff0c\u76f4\u63a5\u63d0\u53d6\u7b2c\u4e00\u5217\u53ef\u80fd\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\u6765\u68c0\u67e5\u6bcf\u4e00\u884c\u7684\u957f\u5ea6\uff0c\u786e\u4fdd\u5b89\u5168\u63d0\u53d6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">data = [[1, 2, 3], [4, 5], [7, 8, 9]]\nfirst_column = [row[0] for row in data if len(row) &gt; 0]\nprint(first_column)  # \u8f93\u51fa\uff1a[1, 4, 7]\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u4e86\u5373\u4f7f\u67d0\u4e9b\u884c\u4e3a\u7a7a\uff0c\u4e5f\u4e0d\u4f1a\u5bfc\u81f4\u7d22\u5f15\u9519\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u63d0\u53d6\u4e00\u4e2a\u6570\u7ec4\u7684\u7b2c\u4e00\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528Numpy\u5e93\u6765\u5b9e\u73b0\u3002\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5207\u7247\u3001\u4f7f\u7528\u7d22\u5f15\u3001\u4ee5\u53caNumpy [&hellip;]","protected":false},"author":3,"featured_media":1044953,"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\/1044949"}],"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=1044949"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1044949\/revisions"}],"predecessor-version":[{"id":1044954,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1044949\/revisions\/1044954"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1044953"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1044949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1044949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1044949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}