{"id":952289,"date":"2024-12-27T01:27:17","date_gmt":"2024-12-26T17:27:17","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/952289.html"},"modified":"2024-12-27T01:27:19","modified_gmt":"2024-12-26T17:27:19","slug":"python-%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89array","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/952289.html","title":{"rendered":"python \u5982\u4f55\u5b9a\u4e49array"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090213\/3b36ab93-69ae-4cb4-8954-0144ceacdf44.webp\" alt=\"python \u5982\u4f55\u5b9a\u4e49array\" \/><\/p>\n<p><p> <strong>\u5728 Python \u4e2d\uff0c\u5b9a\u4e49\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u5f0f\uff0c\u4f8b\u5982\u4f7f\u7528\u5217\u8868\u3001\u4f7f\u7528 NumPy \u5e93\u3001\u4f7f\u7528 array \u6a21\u5757\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528\u5217\u8868\u662f\u6700\u57fa\u7840\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a Python \u7684\u5185\u7f6e\u5217\u8868\u7c7b\u578b\u5df2\u7ecf\u80fd\u591f\u6ee1\u8db3\u8bb8\u591a\u6570\u7ec4\u64cd\u4f5c\u7684\u9700\u6c42\uff1b\u4f46\u662f\u5982\u679c\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6570\u503c\u8ba1\u7b97\uff0cNumPy \u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff1b\u5bf9\u4e8e\u66f4\u7b80\u5355\u7684\u9700\u6c42\uff0carray \u6a21\u5757\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u7c7b\u4f3c C \u8bed\u8a00\u6570\u7ec4\u7684\u529f\u80fd\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e09\u79cd\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\uff1a\u4f7f\u7528 NumPy \u5e93\u3002<\/p>\n<\/p>\n<p><p><strong>NumPy \u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u5f3a\u5927\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u6548\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\uff0c\u79f0\u4e3a ndarray\u3002\u4f7f\u7528 NumPy \u5b9a\u4e49\u6570\u7ec4\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li>\u9996\u5148\u9700\u8981\u5b89\u88c5 NumPy \u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 pip \u547d\u4ee4\uff1a<code>pip install numpy<\/code>\u3002<\/li>\n<li>\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165 NumPy \u5e93\uff1a<code>import numpy as np<\/code>\u3002<\/li>\n<li>\u4f7f\u7528 <code>numpy.array()<\/code> \u51fd\u6570\u6765\u521b\u5efa\u6570\u7ec4\u3002\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u5217\u8868\u3001\u5143\u7ec4\u6216\u5176\u4ed6\u6570\u7ec4\u4f5c\u4e3a\u8f93\u5165\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a NumPy \u6570\u7ec4\u3002<\/li>\n<\/ol>\n<p><p>\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array_1d = np.array([1, 2, 3, 4, 5])<\/p>\n<p>print(array_1d)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u5217\u8868\u521b\u5efa\u6570\u7ec4<\/h2>\n<\/p>\n<p><p>Python \u7684\u5217\u8868\u662f\u5185\u7f6e\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u548c\u64cd\u4f5c\u6570\u7ec4\u3002\u5217\u8868\u662f\u52a8\u6001\u6570\u7ec4\uff0c\u652f\u6301\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u6df7\u5408\u5b58\u50a8\u3002\u4e0b\u9762\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u5217\u8868\u5b9a\u4e49\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h3>1. \u521b\u5efa\u548c\u521d\u59cb\u5316\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u5728 Python \u4e2d\uff0c\u5217\u8868\u662f\u4f7f\u7528\u65b9\u62ec\u53f7 <code>[]<\/code> \u6765\u5b9a\u4e49\u7684\uff0c\u53ef\u4ee5\u76f4\u63a5\u521d\u59cb\u5316\u4e3a\u4e00\u7ec4\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u7a7a\u5217\u8868<\/p>\n<p>empty_list = []<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u521d\u59cb\u5316\u5217\u8868<\/strong><\/h2>\n<p>numbers = [1, 2, 3, 4, 5]<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6df7\u5408\u6570\u636e\u7c7b\u578b\u7684\u5217\u8868<\/strong><\/h2>\n<p>mixed_list = [1, &quot;two&quot;, 3.0, True]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u5217\u8868\u7684\u57fa\u672c\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u652f\u6301\u591a\u79cd\u64cd\u4f5c\uff0c\u4f8b\u5982\u6dfb\u52a0\u3001\u5220\u9664\u3001\u4fee\u6539\u548c\u8bbf\u95ee\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6dfb\u52a0\u5143\u7d20<\/p>\n<p>numbers.append(6)  # \u5728\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u5143\u7d20<\/p>\n<p>numbers.insert(0, 0)  # \u5728\u6307\u5b9a\u4f4d\u7f6e\u63d2\u5165\u5143\u7d20<\/p>\n<h2><strong>\u5220\u9664\u5143\u7d20<\/strong><\/h2>\n<p>numbers.remove(3)  # \u5220\u9664\u503c\u4e3a3\u7684\u5143\u7d20<\/p>\n<p>del numbers[0]  # \u5220\u9664\u7d22\u5f15\u4e3a0\u7684\u5143\u7d20<\/p>\n<h2><strong>\u4fee\u6539\u5143\u7d20<\/strong><\/h2>\n<p>numbers[1] = 10  # \u4fee\u6539\u7d22\u5f15\u4e3a1\u7684\u5143\u7d20\u503c<\/p>\n<h2><strong>\u8bbf\u95ee\u5143\u7d20<\/strong><\/h2>\n<p>first_element = numbers[0]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528 NumPy \u5e93\u521b\u5efa\u6570\u7ec4<\/h2>\n<\/p>\n<p><p>NumPy \u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u6548\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61 ndarray\u3002\u76f8\u6bd4\u4e8e Python \u7684\u5185\u7f6e\u5217\u8868\uff0cNumPy \u6570\u7ec4\u5728\u6027\u80fd\u548c\u529f\u80fd\u4e0a\u6709\u5f88\u5927\u7684\u4f18\u52bf\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5\u548c\u5bfc\u5165 NumPy<\/h3>\n<\/p>\n<p><p>\u9996\u5148\u9700\u8981\u5b89\u88c5 NumPy \u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 pip \u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165 NumPy \u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u521b\u5efa NumPy \u6570\u7ec4<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528 <code>numpy.array()<\/code> \u51fd\u6570\u53ef\u4ee5\u4ece\u5217\u8868\u6216\u5143\u7ec4\u521b\u5efa NumPy \u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u7ef4\u6570\u7ec4<\/p>\n<p>array_1d = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array_2d = np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u521b\u5efa\u4e09\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array_3d = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3. \u6570\u7ec4\u7684\u57fa\u672c\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>NumPy \u6570\u7ec4\u652f\u6301\u591a\u79cd\u64cd\u4f5c\uff0c\u5305\u62ec\u5f62\u72b6\u53d8\u6362\u3001\u5207\u7247\u3001\u6570\u5b66\u8fd0\u7b97\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6570\u7ec4\u5f62\u72b6<\/p>\n<p>print(array_2d.shape)  # \u8f93\u51fa: (2, 3)<\/p>\n<h2><strong>\u6570\u7ec4\u5207\u7247<\/strong><\/h2>\n<p>slice_1d = array_1d[1:4]  # \u8f93\u51fa: [2 3 4]<\/p>\n<p>slice_2d = array_2d[:, 1]  # \u8f93\u51fa: [2 5]<\/p>\n<h2><strong>\u6570\u7ec4\u8fd0\u7b97<\/strong><\/h2>\n<p>sum_array = array_1d + 10  # \u6bcf\u4e2a\u5143\u7d20\u52a010<\/p>\n<p>product_array = array_1d * 2  # \u6bcf\u4e2a\u5143\u7d20\u4e582<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528 array \u6a21\u5757\u521b\u5efa\u6570\u7ec4<\/h2>\n<\/p>\n<p><p>Python \u7684 <code>array<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u7c7b\u4f3c\u4e8e C \u8bed\u8a00\u6570\u7ec4\u7684\u529f\u80fd\uff0c\u9002\u5408\u7528\u4e8e\u7b80\u5355\u7684\u6570\u503c\u6570\u7ec4\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>1. \u5bfc\u5165 array \u6a21\u5757<\/h3>\n<\/p>\n<p><p><code>array<\/code> \u662f Python \u5185\u7f6e\u6a21\u5757\uff0c\u56e0\u6b64\u65e0\u9700\u5b89\u88c5\uff0c\u76f4\u63a5\u5bfc\u5165\u5373\u53ef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import array<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u521b\u5efa\u548c\u521d\u59cb\u5316\u6570\u7ec4<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528 <code>array.array()<\/code> \u51fd\u6570\u53ef\u4ee5\u521b\u5efa\u6570\u7ec4\uff0c\u9700\u8981\u6307\u5b9a\u6570\u7ec4\u7c7b\u578b\u7801\uff08\u5982 &#39;i&#39; \u8868\u793a\u6574\u6570\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u6574\u6570\u6570\u7ec4<\/p>\n<p>int_array = array.array(&#39;i&#39;, [1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6d6e\u70b9\u6570\u6570\u7ec4<\/strong><\/h2>\n<p>float_array = array.array(&#39;f&#39;, [1.0, 2.0, 3.0])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3. \u6570\u7ec4\u7684\u57fa\u672c\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p><code>array<\/code> \u6a21\u5757\u7684\u6570\u7ec4\u652f\u6301\u57fa\u672c\u7684\u64cd\u4f5c\uff0c\u5982\u6dfb\u52a0\u3001\u5220\u9664\u548c\u8bbf\u95ee\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6dfb\u52a0\u5143\u7d20<\/p>\n<p>int_array.append(6)<\/p>\n<h2><strong>\u5220\u9664\u5143\u7d20<\/strong><\/h2>\n<p>int_array.remove(3)<\/p>\n<h2><strong>\u4fee\u6539\u5143\u7d20<\/strong><\/h2>\n<p>int_array[1] = 10<\/p>\n<h2><strong>\u8bbf\u95ee\u5143\u7d20<\/strong><\/h2>\n<p>first_element = int_array[0]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001NumPy \u6570\u7ec4\u7684\u9ad8\u7ea7\u529f\u80fd<\/h2>\n<\/p>\n<p><p>NumPy \u4e0d\u4ec5\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u6570\u7ec4\u64cd\u4f5c\uff0c\u8fd8\u5305\u62ec\u8bb8\u591a\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u5e7f\u64ad\u3001\u7ebf\u6027\u4ee3\u6570\u8fd0\u7b97\u3001\u968f\u673a\u6570\u751f\u6210\u7b49\u3002<\/p>\n<\/p>\n<p><h3>1. \u5e7f\u64ad\u673a\u5236<\/h3>\n<\/p>\n<p><p>\u5e7f\u64ad\u662f\u6307 NumPy \u80fd\u591f\u5728\u4e0d\u540c\u5f62\u72b6\u7684\u6570\u7ec4\u4e4b\u95f4\u8fdb\u884c\u7b97\u672f\u8fd0\u7b97\u7684\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e24\u4e2a\u4e0d\u540c\u5f62\u72b6\u7684\u6570\u7ec4<\/p>\n<p>a = np.array([1, 2, 3])<\/p>\n<p>b = np.array([[1], [2], [3]])<\/p>\n<h2><strong>\u5e7f\u64ad\u673a\u5236\u4e0b\u7684\u52a0\u6cd5\u8fd0\u7b97<\/strong><\/h2>\n<p>result = a + b  # \u8f93\u51fa: [[2 3 4], [3 4 5], [4 5 6]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u7ebf\u6027\u4ee3\u6570\u8fd0\u7b97<\/h3>\n<\/p>\n<p><p>NumPy \u63d0\u4f9b\u4e86\u591a\u79cd\u7ebf\u6027\u4ee3\u6570\u8fd0\u7b97\u51fd\u6570\uff0c\u5982\u77e9\u9635\u4e58\u6cd5\u3001\u9006\u77e9\u9635\u3001\u7279\u5f81\u503c\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u77e9\u9635<\/p>\n<p>matrix = np.array([[1, 2], [3, 4]])<\/p>\n<h2><strong>\u8ba1\u7b97\u9006\u77e9\u9635<\/strong><\/h2>\n<p>inverse_matrix = np.linalg.inv(matrix)<\/p>\n<h2><strong>\u8ba1\u7b97\u77e9\u9635\u4e58\u6cd5<\/strong><\/h2>\n<p>product = np.dot(matrix, inverse_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3. \u968f\u673a\u6570\u751f\u6210<\/h3>\n<\/p>\n<p><p>NumPy \u7684\u968f\u673a\u6570\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u79cd\u968f\u673a\u6570\u751f\u6210\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u5747\u5300\u5206\u5e03\u7684\u968f\u673a\u6570<\/p>\n<p>random_numbers = np.random.rand(3, 2)<\/p>\n<h2><strong>\u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u6570<\/strong><\/h2>\n<p>normal_numbers = np.random.randn(3, 2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u53ef\u4ee5\u770b\u51fa Python \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u5b9a\u4e49\u548c\u64cd\u4f5c\u6570\u7ec4\u3002\u9009\u62e9\u54ea\u79cd\u65b9\u5f0f\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u6027\u80fd\u9700\u6c42\u3002\u5bf9\u4e8e\u4e00\u822c\u7528\u9014\u7684\u6570\u7ec4\u64cd\u4f5c\uff0cPython \u7684\u5217\u8868\u5df2\u7ecf\u8db3\u591f\uff1b\u5bf9\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\uff0cNumPy \u662f\u4e00\u4e2a\u66f4\u4e3a\u5f3a\u5927\u7684\u5de5\u5177\u3002\u800c <code>array<\/code> \u6a21\u5757\u5219\u9002\u5408\u7528\u4e8e\u4e00\u4e9b\u7b80\u5355\u7684\u6570\u503c\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\u521b\u5efa\u6570\u7ec4\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\uff08list\uff09\u6765\u521b\u5efa\u4e00\u4e2a\u52a8\u6001\u6570\u7ec4\uff0c\u6216\u8005\u4f7f\u7528NumPy\u5e93\u4e2d\u7684array\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u66f4\u9ad8\u6548\u7684\u6570\u7ec4\u3002\u82e5\u9009\u62e9\u4f7f\u7528NumPy\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u8be5\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip install numpy<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u521b\u5efaNumPy\u6570\u7ec4\u7684\u57fa\u672c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\narr = np.array([1, 2, 3, 4])\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u521b\u5efa\u7684\u6570\u7ec4\u5177\u6709\u66f4\u9ad8\u7684\u6027\u80fd\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002<\/p>\n<p><strong>Python\u4e2d\u7684\u6570\u7ec4\u548c\u5217\u8868\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><br \/>Python\u7684\u5217\u8868\u662f\u4e00\u79cd\u901a\u7528\u7684\u5e8f\u5217\u7c7b\u578b\uff0c\u53ef\u4ee5\u5305\u542b\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u800cNumPy\u6570\u7ec4\u5219\u662f\u540c\u8d28\u7684\uff0c\u610f\u5473\u7740\u6240\u6709\u5143\u7d20\u90fd\u5fc5\u987b\u662f\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u8fd9\u4f7f\u5f97NumPy\u6570\u7ec4\u5728\u6570\u503c\u8ba1\u7b97\u548c\u79d1\u5b66\u8ba1\u7b97\u4e2d\u66f4\u4e3a\u9ad8\u6548\u3002\u4f7f\u7528\u5217\u8868\u65f6\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\uff0c\u800cNumPy\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u8bbf\u95ee\u6570\u7ec4\u7684\u5143\u7d20\uff1f<\/strong><br \/>\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u7684\u65b9\u6cd5\u4e0e\u8bbf\u95ee\u5217\u8868\u7c7b\u4f3c\u3002\u4f7f\u7528\u7d22\u5f15\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u7279\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u82e5\u5b9a\u4e49\u4e86\u4e00\u4e2aNumPy\u6570\u7ec4<code>arr = np.array([1, 2, 3, 4])<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7<code>arr[0]<\/code>\u8bbf\u95ee\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u8fd4\u56de\u503c\u4e3a<code>1<\/code>\u3002\u5bf9\u4e8e\u591a\u7ef4\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u7d22\u5f15\u8fdb\u884c\u8bbf\u95ee\uff0c\u5982<code>arr[0, 1]<\/code>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728 Python \u4e2d\uff0c\u5b9a\u4e49\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u5f0f\uff0c\u4f8b\u5982\u4f7f\u7528\u5217\u8868\u3001\u4f7f\u7528 NumPy \u5e93\u3001\u4f7f\u7528 array \u6a21\u5757\u3002\u5176 [&hellip;]","protected":false},"author":3,"featured_media":952293,"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\/952289"}],"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=952289"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/952289\/revisions"}],"predecessor-version":[{"id":952294,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/952289\/revisions\/952294"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/952293"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=952289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=952289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=952289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}