{"id":969551,"date":"2024-12-27T05:18:00","date_gmt":"2024-12-26T21:18:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/969551.html"},"modified":"2024-12-27T05:18:02","modified_gmt":"2024-12-26T21:18:02","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e5%8f%98%e9%87%8f%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/969551.html","title":{"rendered":"python\u5982\u4f55\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183801\/279aabc7-8366-47b5-b0df-6d6deafebf04.webp\" alt=\"python\u5982\u4f55\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5217\u8868\u3001\u4f7f\u7528NumPy\u5e93\u3001\u4f7f\u7528\u6570\u7ec4\u6a21\u5757<\/strong>\u3002\u5176\u4e2d\uff0c\u4f7f\u7528\u5217\u8868\u662f\u6700\u5e38\u89c1\u548c\u76f4\u63a5\u7684\u65b9\u5f0f\u3002Python\u7684\u5217\u8868\u662f\u4e00\u79cd\u7075\u6d3b\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5b58\u50a8\u548c\u64cd\u4f5c\u591a\u4e2a\u53d8\u91cf\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528\u5217\u8868\u6765\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><p>Python\u7684\u5217\u8868\u662f\u4e00\u79cd\u5185\u7f6e\u7684\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u591a\u4e2a\u5143\u7d20\u3002\u5217\u8868\u7684\u5b9a\u4e49\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4f7f\u7528\u65b9\u62ec\u53f7\u5c06\u5143\u7d20\u5305\u88f9\u8d77\u6765\uff0c\u5e76\u4ee5\u9017\u53f7\u5206\u9694\u5373\u53ef\u3002\u4f8b\u5982\uff0c\u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u6574\u6570\u7684\u5217\u8868\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">integer_list = [1, 2, 3, 4, 5]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5217\u8868\u4e0d\u4ec5\u53ef\u4ee5\u5b58\u50a8\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u8fd8\u53ef\u4ee5\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u8fd9\u662f\u56e0\u4e3aPython\u662f\u52a8\u6001\u7c7b\u578b\u8bed\u8a00\uff0c\u5217\u8868\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u6574\u6570\u3001\u5b57\u7b26\u4e32\u3001\u6d6e\u70b9\u6570\uff0c\u751a\u81f3\u662f\u5176\u4ed6\u5217\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">mixed_list = [1, &quot;two&quot;, 3.0, [4, 5]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u7075\u6d3b\u6027\u4f7f\u5f97Python\u7684\u5217\u8868\u5728\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4\u65f6\u975e\u5e38\u5b9e\u7528\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8Python\u4e2d\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4\u7684\u51e0\u79cd\u5e38\u7528\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5217\u8868\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u57fa\u672c\u5217\u8868<\/strong><\/li>\n<\/ol>\n<p><p>\u5217\u8868\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u4e4b\u4e00\u3002\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u5b58\u50a8\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u8fd8\u53ef\u4ee5\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\u3002\u521b\u5efa\u5217\u8868\u7684\u8bed\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u4f7f\u7528\u65b9\u62ec\u53f7\u5c06\u5143\u7d20\u5305\u88f9\u8d77\u6765\uff0c\u7528\u9017\u53f7\u5206\u9694\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>fruits<\/code>\u662f\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u5b57\u7b26\u4e32\u5143\u7d20\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5217\u8868\u7684\u52a8\u6001\u7279\u6027<\/strong><\/li>\n<\/ol>\n<p><p>Python\u7684\u5217\u8868\u662f\u52a8\u6001\u7684\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u968f\u65f6\u6dfb\u52a0\u3001\u5220\u9664\u6216\u4fee\u6539\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u6dfb\u52a0\u5143\u7d20<\/strong>\uff1a\u4f7f\u7528<code>append()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5728\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fruits.append(&quot;orange&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5220\u9664\u5143\u7d20<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528<code>remove()<\/code>\u65b9\u6cd5\u5220\u9664\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\uff0c\u6216\u4f7f\u7528<code>del<\/code>\u5173\u952e\u5b57\u5220\u9664\u6307\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fruits.remove(&quot;banana&quot;)<\/p>\n<p>del fruits[1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fee\u6539\u5143\u7d20<\/strong>\uff1a\u76f4\u63a5\u901a\u8fc7\u7d22\u5f15\u6765\u4fee\u6539\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fruits[0] = &quot;kiwi&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<ol start=\"3\">\n<li><strong>\u5217\u8868\u7684\u904d\u5386<\/strong><\/li>\n<\/ol>\n<p><p>\u904d\u5386\u5217\u8868\u662fPython\u4e2d\u975e\u5e38\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u53ef\u4ee5\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u6765\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for fruit in fruits:<\/p>\n<p>    print(fruit)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u7b80\u6d01\u800c\u5f3a\u5927\u7684\u7279\u6027\u4f7f\u5f97\u5217\u8868\u5728Python\u7f16\u7a0b\u4e2d\u5f97\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528NumPy\u5e93\u5b9a\u4e49\u6570\u7ec4<\/p>\n<\/p>\n<ol>\n<li><strong>NumPy\u7b80\u4ecb<\/strong><\/li>\n<\/ol>\n<p><p>NumPy\u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684Python\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u7ec4\u5bf9\u8c61<code>ndarray<\/code>\uff0c\u652f\u6301\u591a\u79cd\u6570\u5b66\u8fd0\u7b97\u548c\u64cd\u4f5c\u3002\u4e0ePython\u7684\u5185\u7f6e\u5217\u8868\u76f8\u6bd4\uff0cNumPy\u6570\u7ec4\u5177\u6709\u66f4\u9ad8\u7684\u6548\u7387\u548c\u66f4\u5f3a\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b89\u88c5NumPy<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528NumPy\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5\u8be5\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u521b\u5efaNumPy\u6570\u7ec4<\/strong><\/li>\n<\/ol>\n<p><p>\u521b\u5efaNumPy\u6570\u7ec4\u6709\u591a\u79cd\u65b9\u5f0f\uff0c\u6700\u5e38\u7528\u7684\u662f\u4f7f\u7528<code>array()<\/code>\u51fd\u6570\uff0c\u5c06\u4e00\u4e2a\u5217\u8868\u6216\u5143\u7ec4\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>num_array = np.array([1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u6570\u7ec4\u7684\u591a\u7ef4\u6027<\/strong><\/li>\n<\/ol>\n<p><p>NumPy\u6570\u7ec4\u4e0d\u4ec5\u652f\u6301\u4e00\u7ef4\uff0c\u8fd8\u652f\u6301\u591a\u7ef4\u6570\u7ec4\uff0c\u521b\u5efa\u591a\u7ef4\u6570\u7ec4\u7684\u65b9\u5f0f\u4e0e\u4e00\u7ef4\u7c7b\u4f3c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">multi_array = np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"5\">\n<li><strong>\u6570\u7ec4\u7684\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n<p><p>NumPy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u7ec4\u64cd\u4f5c\u51fd\u6570\uff0c\u5982\u5207\u7247\u3001\u5f62\u72b6\u53d8\u6362\u3001\u6570\u5b66\u8fd0\u7b97\u7b49\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5207\u7247<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7\u5207\u7247\u64cd\u4f5c\u83b7\u53d6\u6570\u7ec4\u7684\u5b50\u96c6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sub_array = num_array[1:4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5f62\u72b6\u53d8\u6362<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528<code>reshape()<\/code>\u65b9\u6cd5\u6539\u53d8\u6570\u7ec4\u7684\u5f62\u72b6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">reshaped_array = num_array.reshape(5, 1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u5b66\u8fd0\u7b97<\/strong>\uff1aNumPy\u652f\u6301\u6570\u7ec4\u7684\u5143\u7d20\u7ea7\u8fd0\u7b97\uff0c\u5982\u52a0\u51cf\u4e58\u9664\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result = num_array + 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u4e09\u3001\u4f7f\u7528\u6570\u7ec4\u6a21\u5757<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u7ec4\u6a21\u5757\u7b80\u4ecb<\/strong><\/li>\n<\/ol>\n<p><p>Python\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5185\u7f6e\u7684\u6570\u7ec4\u6a21\u5757<code>array<\/code>\uff0c\u7528\u4e8e\u5904\u7406\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u6570\u7ec4\u3002\u4e0eNumPy\u4e0d\u540c\uff0c<code>array<\/code>\u6a21\u5757\u7684\u6570\u7ec4\u4ec5\u9650\u4e8e\u5b58\u50a8\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u521b\u5efa\u6570\u7ec4<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u6570\u7ec4\u6a21\u5757\u521b\u5efa\u6570\u7ec4\u9700\u8981\u6307\u5b9a\u5143\u7d20\u7684\u7c7b\u578b\u4ee3\u7801\uff0c\u5982&#39;i&#39;\u8868\u793a\u6574\u6570\uff0c&#39;f&#39;\u8868\u793a\u6d6e\u70b9\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import array<\/p>\n<p>int_array = array.array(&#39;i&#39;, [1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6570\u7ec4\u7684\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n<p><p>\u6570\u7ec4\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u6570\u7ec4\u64cd\u4f5c\uff0c\u4f46\u529f\u80fd\u4e0d\u5982NumPy\u4e30\u5bcc\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u6dfb\u52a0\u5143\u7d20<\/strong>\uff1a\u4f7f\u7528<code>append()<\/code>\u65b9\u6cd5\u5728\u6570\u7ec4\u672b\u5c3e\u6dfb\u52a0\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">int_array.append(6)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u63d2\u5165\u5143\u7d20<\/strong>\uff1a\u4f7f\u7528<code>insert()<\/code>\u65b9\u6cd5\u5728\u6307\u5b9a\u4f4d\u7f6e\u63d2\u5165\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">int_array.insert(2, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5220\u9664\u5143\u7d20<\/strong>\uff1a\u4f7f\u7528<code>remove()<\/code>\u65b9\u6cd5\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">int_array.remove(3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u56db\u3001\u5217\u8868\u4e0eNumPy\u6570\u7ec4\u7684\u5bf9\u6bd4<\/p>\n<\/p>\n<ol>\n<li><strong>\u6027\u80fd<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\uff0cNumPy\u6570\u7ec4\u7684\u6027\u80fd\u660e\u663e\u4f18\u4e8ePython\u5217\u8868\u3002\u8fd9\u662f\u56e0\u4e3aNumPy\u6570\u7ec4\u91c7\u7528\u8fde\u7eed\u5185\u5b58\u5b58\u50a8\uff0c\u4f7f\u5f97\u6570\u5b66\u8fd0\u7b97\u66f4\u9ad8\u6548\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u529f\u80fd<\/strong><\/li>\n<\/ol>\n<p><p>NumPy\u6570\u7ec4\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\u548c\u64cd\u4f5c\uff0c\u5982\u77e9\u9635\u8fd0\u7b97\u3001\u5085\u91cc\u53f6\u53d8\u6362\u7b49\uff0c\u9002\u5408\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u7075\u6d3b\u6027<\/strong><\/li>\n<\/ol>\n<p><p>Python\u5217\u8868\u66f4\u4e3a\u7075\u6d3b\uff0c\u53ef\u4ee5\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u800cNumPy\u6570\u7ec4\u4ec5\u9650\u4e8e\u5b58\u50a8\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5e94\u7528\u573a\u666f<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u5206\u6790<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\u4e2d\uff0cNumPy\u6570\u7ec4\u662f\u9996\u9009\u7684\u6570\u636e\u7ed3\u6784\u3002\u5176\u9ad8\u6548\u7684\u8ba1\u7b97\u80fd\u529b\u548c\u4e30\u5bcc\u7684\u51fd\u6570\u5e93\u4f7f\u5176\u6210\u4e3a\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u7684\u5229\u5668\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7b80\u5355\u6570\u636e\u5b58\u50a8<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u7b80\u5355\u7684\u6570\u636e\u5b58\u50a8\u548c\u64cd\u4f5c\uff0cPython\u7684\u5217\u8868\u5df2\u7ecf\u8db3\u591f\u3002\u5b83\u7684\u7075\u6d3b\u6027\u4f7f\u5176\u53ef\u4ee5\u8f7b\u677e\u5904\u7406\u5404\u79cd\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u9700\u8981\u9ad8\u6548\u8ba1\u7b97\u7684\u573a\u666f<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53\u9700\u8981\u8fdb\u884c\u5927\u91cf\u7684\u6570\u5b66\u8fd0\u7b97\u6216\u6570\u636e\u5904\u7406\u65f6\uff0cNumPy\u6570\u7ec4\u7684\u6027\u80fd\u4f18\u52bf\u5c06\u663e\u73b0\u65e0\u9057\u3002\u56e0\u6b64\uff0c\u5728\u8fd9\u4e9b\u573a\u666f\u4e2d\uff0c\u4f18\u5148\u9009\u62e9NumPy\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4\u7684\u65b9\u6cd5\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\u548c\u9002\u7528\u573a\u666f\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\u548c\u53ef\u8bfb\u6027\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\u6570\u7ec4\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u521b\u5efa\u6570\u7ec4\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\uff08list\uff09\u6216NumPy\u5e93\u3002\u4f7f\u7528\u5217\u8868\u7684\u65b9\u5f0f\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u901a\u8fc7\u65b9\u62ec\u53f7\u5c06\u591a\u4e2a\u503c\u653e\u5728\u4e00\u8d77\u3002\u4f8b\u5982\uff1a<code>my_array = [1, 2, 3, 4]<\/code>\u3002\u5982\u679c\u9700\u8981\u66f4\u590d\u6742\u7684\u6570\u7ec4\u64cd\u4f5c\uff0c\u6bd4\u5982\u591a\u7ef4\u6570\u7ec4\uff0cNumPy\u662f\u4e00\u4e2a\u66f4\u5408\u9002\u7684\u9009\u62e9\u3002\u9996\u5148\u9700\u8981\u5b89\u88c5NumPy\u5e93\uff0c\u4f7f\u7528<code>pip install numpy<\/code>\uff0c\u7136\u540e\u53ef\u4ee5\u901a\u8fc7<code>import numpy as np<\/code>\u5bfc\u5165\uff0c\u5e76\u4f7f\u7528<code>np.array()<\/code>\u51fd\u6570\u521b\u5efa\u6570\u7ec4\uff0c\u5982<code>my_array = np.array([1, 2, 3, 4])<\/code>\u3002<\/p>\n<p><strong>Python\u4e2d\u7684\u6570\u7ec4\u548c\u5217\u8868\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6570\u7ec4\u548c\u5217\u8868\u5728\u67d0\u4e9b\u65b9\u9762\u662f\u4e0d\u540c\u7684\u3002\u5217\u8868\u662fPython\u5185\u7f6e\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u5305\u542b\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u800c\u6570\u7ec4\u901a\u5e38\u662f\u901a\u8fc7NumPy\u5e93\u5b9e\u73b0\u7684\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u6570\u503c\u6570\u636e\uff0c\u5e76\u4e14\u5728\u6027\u80fd\u4e0a\u66f4\u4f18\u3002NumPy\u6570\u7ec4\u5177\u6709\u56fa\u5b9a\u7684\u7c7b\u578b\uff0c\u9002\u5408\u8fdb\u884c\u5927\u91cf\u7684\u6570\u503c\u8ba1\u7b97\uff0c\u540c\u65f6\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\u3002<\/p>\n<p><strong>\u5982\u4f55\u8bbf\u95ee\u548c\u4fee\u6539Python\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1f<\/strong><br \/>\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20\u975e\u5e38\u7b80\u5355\u3002\u5bf9\u4e8e\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u6765\u8bbf\u95ee\u7279\u5b9a\u5143\u7d20\uff0c\u4f8b\u5982<code>my_array[0]<\/code>\u83b7\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002\u8981\u4fee\u6539\u5143\u7d20\uff0c\u53ef\u4ee5\u76f4\u63a5\u8d4b\u503c\uff0c\u4f8b\u5982<code>my_array[0] = 10<\/code>\u3002\u5bf9\u4e8eNumPy\u6570\u7ec4\uff0c\u65b9\u6cd5\u7c7b\u4f3c\uff0c\u4f46\u8981\u786e\u4fdd\u7d22\u5f15\u5728\u6570\u7ec4\u7684\u8303\u56f4\u5185\u3002\u4f7f\u7528<code>my_array[0]<\/code>\u83b7\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u4f7f\u7528<code>my_array[0] = 10<\/code>\u4fee\u6539\u5b83\u3002\u6ce8\u610f\uff0cNumPy\u6570\u7ec4\u7684\u7d22\u5f15\u4ece0\u5f00\u59cb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5b9a\u4e49\u53d8\u91cf\u6570\u7ec4\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5217\u8868\u3001\u4f7f\u7528NumPy\u5e93\u3001\u4f7f\u7528\u6570\u7ec4\u6a21\u5757\u3002\u5176\u4e2d\uff0c\u4f7f\u7528\u5217\u8868\u662f\u6700\u5e38\u89c1\u548c\u76f4\u63a5 [&hellip;]","protected":false},"author":3,"featured_media":969554,"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\/969551"}],"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=969551"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/969551\/revisions"}],"predecessor-version":[{"id":969555,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/969551\/revisions\/969555"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/969554"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=969551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=969551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=969551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}