{"id":1089908,"date":"2025-01-08T13:57:42","date_gmt":"2025-01-08T05:57:42","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1089908.html"},"modified":"2025-01-08T13:57:46","modified_gmt":"2025-01-08T05:57:46","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e6%8f%90%e5%8f%96%e7%9f%a9%e9%98%b5%e4%b8%ad%e7%9a%84%e5%85%83%e7%b4%a0-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1089908.html","title":{"rendered":"\u5982\u4f55\u7528python\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24202616\/3ab2369e-19fc-4525-a2df-bf0416145217.webp\" alt=\"\u5982\u4f55\u7528python\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u7528Python\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002<strong>\u65b9\u6cd5\u5305\u62ec\u76f4\u63a5\u7d22\u5f15\u3001\u5207\u7247\u3001NumPy\u5e93\u7684\u9ad8\u7ea7\u7d22\u5f15\u3001\u6761\u4ef6\u7d22\u5f15<\/strong>\u3002\u5176\u4e2d\uff0c<strong>NumPy\u5e93\u63d0\u4f9b\u4e86\u66f4\u52a0\u5f3a\u5927\u548c\u7075\u6d3b\u7684\u77e9\u9635\u64cd\u4f5c\u5de5\u5177<\/strong>\uff0c\u662f\u5904\u7406\u77e9\u9635\u7684\u9996\u9009\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u91cd\u70b9\u8bb2\u89e3\u5982\u4f55\u4f7f\u7528NumPy\u5e93\u6765\u8fdb\u884c\u77e9\u9635\u5143\u7d20\u7684\u63d0\u53d6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5217\u8868\u7d22\u5f15\u548c\u5207\u7247<\/p>\n<\/p>\n<p><p>Python\u5185\u7f6e\u7684\u5217\u8868\uff08List\uff09\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u548c\u64cd\u4f5c\u77e9\u9635\u3002\u901a\u8fc7\u5217\u8868\u7d22\u5f15\u548c\u5207\u7247\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<ol>\n<li>\u521b\u5efa\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u6765\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u63d0\u53d6\u5355\u4e2a\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u8981\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5355\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u91cd\u7d22\u5f15\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = matrix[1][2]<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u63d0\u53d6\u4e00\u884c\u6216\u4e00\u5217<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u64cd\u4f5c\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u4e00\u884c\u6216\u4e00\u5217\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u7b2c\u4e00\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">row = matrix[0]<\/p>\n<p>print(row)  # \u8f93\u51fa\uff1a[1, 2, 3]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63d0\u53d6\u7b2c\u4e00\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">column = [row[0] for row in matrix]<\/p>\n<p>print(column)  # \u8f93\u51fa\uff1a[1, 4, 7]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u63d0\u53d6\u5b50\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u5d4c\u5957\u7684\u5207\u7247\u64cd\u4f5c\u6765\u63d0\u53d6\u5b50\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u4e00\u4e2a2&#215;2\u7684\u5b50\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sub_matrix = [row[:2] for row in matrix[:2]]<\/p>\n<p>print(sub_matrix)  # \u8f93\u51fa\uff1a[[1, 2], [4, 5]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528NumPy\u5e93<\/p>\n<\/p>\n<p><p>NumPy\u662fPython\u4e2d\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u4e30\u5bcc\u7684\u51fd\u6570\u5e93\uff0c\u7528\u4e8e\u9ad8\u6548\u5730\u8fdb\u884c\u77e9\u9635\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<ol>\n<li>\u521b\u5efa\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528NumPy\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u521b\u5efa\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>matrix = np.array([<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u63d0\u53d6\u5355\u4e2a\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u8981\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5355\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u91cd\u7d22\u5f15\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = matrix[1, 2]<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u63d0\u53d6\u4e00\u884c\u6216\u4e00\u5217<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u64cd\u4f5c\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u4e00\u884c\u6216\u4e00\u5217\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u7b2c\u4e00\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">row = matrix[0, :]<\/p>\n<p>print(row)  # \u8f93\u51fa\uff1a[1 2 3]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63d0\u53d6\u7b2c\u4e00\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">column = matrix[:, 0]<\/p>\n<p>print(column)  # \u8f93\u51fa\uff1a[1 4 7]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u63d0\u53d6\u5b50\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u5207\u7247\u64cd\u4f5c\u6765\u63d0\u53d6\u5b50\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u4e00\u4e2a2&#215;2\u7684\u5b50\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sub_matrix = matrix[:2, :2]<\/p>\n<p>print(sub_matrix)  # \u8f93\u51fa\uff1a[[1 2]<\/p>\n<p>                   #       [4 5]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"5\">\n<li>\u6761\u4ef6\u7d22\u5f15<\/li>\n<\/ol>\n<p><p>NumPy\u8fd8\u652f\u6301\u6761\u4ef6\u7d22\u5f15\uff0c\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u5927\u4e8e5\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">elements = matrix[matrix &gt; 5]<\/p>\n<p>print(elements)  # \u8f93\u51fa\uff1a[6 7 8 9]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u9ad8\u7ea7\u7d22\u5f15<\/p>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86\u9ad8\u7ea7\u7d22\u5f15\u529f\u80fd\uff0c\u53ef\u4ee5\u6839\u636e\u7d22\u5f15\u6570\u7ec4\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6309\u7167\u7d22\u5f15\u6570\u7ec4\u63d0\u53d6\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u4f8b\u5982\uff0c\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u6307\u5b9a\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">indices = [0, 2, 1]<\/p>\n<p>elements = matrix[indices, indices]<\/p>\n<p>print(elements)  # \u8f93\u51fa\uff1a[1 8 6]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528\u5e03\u5c14\u6570\u7ec4\u7d22\u5f15<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5e03\u5c14\u6570\u7ec4\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5076\u6570\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">bool_array = (matrix % 2 == 0)<\/p>\n<p>even_elements = matrix[bool_array]<\/p>\n<p>print(even_elements)  # \u8f93\u51fa\uff1a[2 4 6 8]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u4f7f\u7528\u82b1\u5f0f\u7d22\u5f15<\/li>\n<\/ol>\n<p><p>NumPy\u8fd8\u652f\u6301\u82b1\u5f0f\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u7d22\u5f15\u6570\u7ec4\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u6307\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">rows = [0, 1, 2]<\/p>\n<p>cols = [2, 1, 0]<\/p>\n<p>elements = matrix[rows, cols]<\/p>\n<p>print(elements)  # \u8f93\u51fa\uff1a[3 5 7]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u77e9\u9635\u8fd0\u7b97\u63d0\u53d6\u5143\u7d20<\/p>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u77e9\u9635\u8fd0\u7b97\u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u77e9\u9635\u8fd0\u7b97\u6765\u63d0\u53d6\u7279\u5b9a\u5143\u7d20\u3002<\/p>\n<\/p>\n<ol>\n<li>\u63d0\u53d6\u5bf9\u89d2\u7ebf\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528NumPy\u7684\u5bf9\u89d2\u7ebf\u51fd\u6570\u6765\u63d0\u53d6\u77e9\u9635\u7684\u5bf9\u89d2\u7ebf\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">diagonal = np.diag(matrix)<\/p>\n<p>print(diagonal)  # \u8f93\u51fa\uff1a[1 5 9]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u63d0\u53d6\u4e0a\u4e09\u89d2\u548c\u4e0b\u4e09\u89d2\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528NumPy\u7684\u4e0a\u4e09\u89d2\u548c\u4e0b\u4e09\u89d2\u51fd\u6570\u6765\u63d0\u53d6\u77e9\u9635\u7684\u4e0a\u4e09\u89d2\u548c\u4e0b\u4e09\u89d2\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">upper_triangle = np.triu(matrix)<\/p>\n<p>lower_triangle = np.tril(matrix)<\/p>\n<p>print(upper_triangle)  # \u8f93\u51fa\uff1a[[1 2 3]<\/p>\n<p>                       #       [0 5 6]<\/p>\n<p>                       #       [0 0 9]]<\/p>\n<p>print(lower_triangle)  # \u8f93\u51fa\uff1a[[1 0 0]<\/p>\n<p>                       #       [4 5 0]<\/p>\n<p>                       #       [7 8 9]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528Pandas\u5e93<\/p>\n<\/p>\n<p><p>Pandas\u662fPython\u4e2d\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u63d0\u4f9b\u4e86DataFrame\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u4e8e\u64cd\u4f5c\u77e9\u9635\u3002<\/p>\n<\/p>\n<ol>\n<li>\u521b\u5efa\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Pandas\u7684DataFrame\u6765\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>matrix = pd.DataFrame([<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u63d0\u53d6\u5355\u4e2a\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u8981\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5355\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528iat\u6216iloc\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = matrix.iat[1, 2]<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a6<\/p>\n<p>element = matrix.iloc[1, 2]<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u63d0\u53d6\u4e00\u884c\u6216\u4e00\u5217<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528loc\u6216iloc\u65b9\u6cd5\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u4e00\u884c\u6216\u4e00\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">row = matrix.iloc[0, :]<\/p>\n<p>print(row)  # \u8f93\u51fa\uff1a<\/p>\n<p>            # 0    1<\/p>\n<p>            # 1    2<\/p>\n<p>            # 2    3<\/p>\n<p>            # Name: 0, dtype: int64<\/p>\n<p>column = matrix.iloc[:, 0]<\/p>\n<p>print(column)  # \u8f93\u51fa\uff1a<\/p>\n<p>               # 0    1<\/p>\n<p>               # 1    4<\/p>\n<p>               # 2    7<\/p>\n<p>               # Name: 0, dtype: int64<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u63d0\u53d6\u5b50\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u901a\u8fc7loc\u6216iloc\u65b9\u6cd5\u6765\u63d0\u53d6\u5b50\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sub_matrix = matrix.iloc[:2, :2]<\/p>\n<p>print(sub_matrix)  # \u8f93\u51fa\uff1a<\/p>\n<p>                   #    0  1<\/p>\n<p>                   # 0  1  2<\/p>\n<p>                   # 1  4  5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\uff0c\u5305\u62ec\u4f7f\u7528\u5217\u8868\u7d22\u5f15\u548c\u5207\u7247\u3001NumPy\u5e93\u3001Pandas\u5e93\u4ee5\u53ca\u9ad8\u7ea7\u7d22\u5f15\u548c\u77e9\u9635\u8fd0\u7b97\u7684\u65b9\u6cd5\u3002<strong>NumPy\u5e93\u63d0\u4f9b\u4e86\u66f4\u52a0\u5f3a\u5927\u548c\u7075\u6d3b\u7684\u77e9\u9635\u64cd\u4f5c\u5de5\u5177<\/strong>\uff0c\u662f\u5904\u7406\u77e9\u9635\u7684\u9996\u9009\u3002\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u8fdb\u884c\u77e9\u9635\u64cd\u4f5c\uff0c\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u63d0\u53d6\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u77e9\u9635\u5143\u7d20\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u5229\u7528NumPy\u5e93\u8f7b\u677e\u63d0\u53d6\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u77e9\u9635\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u5e03\u5c14\u7d22\u5f15\u53ef\u4ee5\u7b5b\u9009\u51fa\u5927\u4e8e\u67d0\u4e2a\u9608\u503c\u7684\u6240\u6709\u5143\u7d20\u3002\u53ea\u9700\u5bf9\u77e9\u9635\u5e94\u7528\u6761\u4ef6\u8868\u8fbe\u5f0f\u5e76\u5c06\u7ed3\u679c\u4f5c\u4e3a\u7d22\u5f15\uff0c\u5c31\u80fd\u83b7\u5f97\u6240\u9700\u7684\u5143\u7d20\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u63d0\u53d6\u77e9\u9635\u884c\u6216\u5217\u7684\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u63d0\u53d6\u77e9\u9635\u7684\u884c\u6216\u5217\u53ef\u4ee5\u901a\u8fc7\u6570\u7ec4\u5207\u7247\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>matrix[row_index]<\/code>\u53ef\u4ee5\u63d0\u53d6\u7279\u5b9a\u884c\uff0c\u4f7f\u7528<code>matrix[:, column_index]<\/code>\u53ef\u4ee5\u63d0\u53d6\u7279\u5b9a\u5217\u3002NumPy\u7684\u5f3a\u5927\u529f\u80fd\u4f7f\u5f97\u8fd9\u4e00\u64cd\u4f5c\u53d8\u5f97\u975e\u5e38\u7b80\u5355\u548c\u76f4\u89c2\u3002<\/p>\n<p><strong>\u5982\u4f55\u63d0\u53d6\u77e9\u9635\u4e2d\u67d0\u4e2a\u5b50\u77e9\u9635\u7684\u5143\u7d20\uff1f<\/strong><br \/>\u8981\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5b50\u77e9\u9635\uff0c\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u8bed\u6cd5\u6307\u5b9a\u884c\u548c\u5217\u7684\u8303\u56f4\u3002\u4f8b\u5982\uff0c<code>matrix[start_row:end_row, start_column:end_column]<\/code>\u53ef\u4ee5\u63d0\u53d6\u4ece\u8d77\u59cb\u884c\u5230\u7ed3\u675f\u884c\uff0c\u4ee5\u53ca\u4ece\u8d77\u59cb\u5217\u5230\u7ed3\u675f\u5217\u7684\u5b50\u77e9\u9635\u3002\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u7684\u5207\u5272\u548c\u5206\u6790\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u7528Python\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20 \u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u63d0\u53d6\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002\u65b9\u6cd5\u5305\u62ec\u76f4\u63a5\u7d22\u5f15\u3001\u5207 [&hellip;]","protected":false},"author":3,"featured_media":1089918,"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\/1089908"}],"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=1089908"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1089908\/revisions"}],"predecessor-version":[{"id":1089919,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1089908\/revisions\/1089919"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1089918"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1089908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1089908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1089908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}