{"id":1124486,"date":"2025-01-08T19:42:01","date_gmt":"2025-01-08T11:42:01","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1124486.html"},"modified":"2025-01-08T19:42:03","modified_gmt":"2025-01-08T11:42:03","slug":"python%e5%a6%82%e4%bd%95%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e5%9b%9b%e7%bb%b4%e7%9f%a9%e9%98%b5","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1124486.html","title":{"rendered":"python\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085517\/e7795ba2-2429-4d2f-b8cf-7927566edff6.webp\" alt=\"python\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528NumPy\u5e93\u3002<\/strong> NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5e93\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u5927\u578b\u591a\u7ef4\u6570\u7ec4\u548c\u77e9\u9635\u8fd0\u7b97\uff0c\u540c\u65f6\u4e5f\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u6570\u5b66\u51fd\u6570\u3002\u4e3a\u4e86\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528NumPy\u7684<code>numpy.ndarray<\/code>\u7c7b\u6216\u8005<code>numpy.zeros<\/code>\u3001<code>numpy.ones<\/code>\u7b49\u51fd\u6570\u6765\u521d\u59cb\u5316\u77e9\u9635\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u5b89\u88c5\u548c\u5bfc\u5165NumPy\u5e93<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u521b\u5efa\u56db\u7ef4\u77e9\u9635\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\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><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165NumPy\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528<code>numpy.zeros<\/code>\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528<code>numpy.zeros<\/code>\u51fd\u6570\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5168\u4e3a\u96f6\u7684\u56db\u7ef4\u77e9\u9635\u3002\u8be5\u51fd\u6570\u9700\u8981\u4e00\u4e2a\u5f62\u72b6\uff08shape\uff09\u53c2\u6570\uff0c\u6307\u5b9a\u77e9\u9635\u7684\u5404\u4e2a\u7ef4\u5ea6\u5927\u5c0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a4x3x2x5\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u521d\u59cb\u5316\u4e3a0<\/p>\n<p>shape = (4, 3, 2, 5)<\/p>\n<p>matrix_4d = np.zeros(shape)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>shape<\/code>\u662f\u4e00\u4e2a\u5305\u542b\u56db\u4e2a\u7ef4\u5ea6\u5927\u5c0f\u7684\u5143\u7ec4\u3002<code>np.zeros(shape)<\/code>\u5c06\u8fd4\u56de\u4e00\u4e2a\u5f62\u72b6\u4e3a<code>(4, 3, 2, 5)<\/code>\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u521d\u59cb\u5316\u4e3a0\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528<code>numpy.ones<\/code>\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635<\/h2>\n<\/p>\n<p><p>\u7c7b\u4f3c\u5730\uff0c\u53ef\u4ee5\u4f7f\u7528<code>numpy.ones<\/code>\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5168\u4e3a\u4e00\u7684\u56db\u7ef4\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a4x3x2x5\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u521d\u59cb\u5316\u4e3a1<\/p>\n<p>shape = (4, 3, 2, 5)<\/p>\n<p>matrix_4d = np.ones(shape)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>np.ones(shape)<\/code>\u5c06\u8fd4\u56de\u4e00\u4e2a\u5f62\u72b6\u4e3a<code>(4, 3, 2, 5)<\/code>\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u521d\u59cb\u5316\u4e3a1\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u4f7f\u7528<code>numpy.random<\/code>\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u56db\u7ef4\u77e9\u9635<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u4e00\u4e2a\u5305\u542b\u968f\u673a\u6570\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u53ef\u4ee5\u4f7f\u7528<code>numpy.random<\/code>\u6a21\u5757\u4e0b\u7684<code>rand<\/code>\u6216\u8005<code>randn<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a4x3x2x5\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u4e3a0\u52301\u4e4b\u95f4\u7684\u968f\u673a\u6570<\/p>\n<p>shape = (4, 3, 2, 5)<\/p>\n<p>matrix_4d = np.random.rand(*shape)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>np.random.rand(*shape)<\/code>\u5c06\u8fd4\u56de\u4e00\u4e2a\u5f62\u72b6\u4e3a<code>(4, 3, 2, 5)<\/code>\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u662f0\u52301\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u4f7f\u7528<code>numpy.ndarray<\/code>\u7c7b\u521b\u5efa\u81ea\u5b9a\u4e49\u56db\u7ef4\u77e9\u9635<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u66f4\u7075\u6d3b\u7684\u521d\u59cb\u5316\u65b9\u5f0f\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>numpy.ndarray<\/code>\u7c7b\u6765\u521b\u5efa\u56db\u7ef4\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u7a7a\u76844x3x2x5\u7684\u56db\u7ef4\u77e9\u9635<\/p>\n<p>shape = (4, 3, 2, 5)<\/p>\n<p>matrix_4d = np.ndarray(shape)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>np.ndarray(shape)<\/code>\u5c06\u8fd4\u56de\u4e00\u4e2a\u5f62\u72b6\u4e3a<code>(4, 3, 2, 5)<\/code>\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u4f46\u5176\u4e2d\u7684\u5143\u7d20\u672a\u88ab\u521d\u59cb\u5316\uff0c\u56e0\u6b64\u53ef\u80fd\u5305\u542b\u4efb\u610f\u503c\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u64cd\u4f5c\u56db\u7ef4\u77e9\u9635<\/h2>\n<\/p>\n<p><p>\u521b\u5efa\u56db\u7ef4\u77e9\u9635\u4e4b\u540e\uff0c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u4f8b\u5982\u8bbf\u95ee\u3001\u4fee\u6539\u3001\u5207\u7247\u7b49\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u8bbf\u95ee\u548c\u4fee\u6539\u5143\u7d20<\/h3>\n<\/p>\n<p><p>\u8bbf\u95ee\u548c\u4fee\u6539\u56db\u7ef4\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u4f7f\u7528\u591a\u91cd\u7d22\u5f15\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bbf\u95ee4x3x2x5\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20<\/p>\n<p>element = matrix_4d[1, 2, 0, 4]<\/p>\n<h2><strong>\u4fee\u65394x3x2x5\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20<\/strong><\/h2>\n<p>matrix_4d[1, 2, 0, 4] = 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u5207\u7247\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u64cd\u4f5c\u6765\u8bbf\u95ee\u56db\u7ef4\u77e9\u9635\u4e2d\u7684\u5b50\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bbf\u95ee4x3x2x5\u77e9\u9635\u4e2d\u7684\u5b50\u77e9\u9635<\/p>\n<p>sub_matrix = matrix_4d[0:2, 1:3, :, :]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>sub_matrix<\/code>\u5c06\u5305\u542b<code>matrix_4d<\/code>\u4e2d\u7684\u4e00\u4e2a\u5b50\u77e9\u9635\uff0c\u5f62\u72b6\u4e3a<code>(2, 2, 2, 5)<\/code>\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u77e9\u9635\u8fd0\u7b97<\/h3>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u77e9\u9635\u8fd0\u7b97\u51fd\u6570\uff0c\u53ef\u4ee5\u5bf9\u56db\u7ef4\u77e9\u9635\u8fdb\u884c\u5404\u79cd\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bf94x3x2x5\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8fdb\u884c\u52a0\u6cd5\u8fd0\u7b97<\/p>\n<p>matrix_4d = matrix_4d + 2<\/p>\n<h2><strong>\u5bf94x3x2x5\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8fdb\u884c\u4e58\u6cd5\u8fd0\u7b97<\/strong><\/h2>\n<p>matrix_4d = matrix_4d * 3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u77e9\u9635\u53d8\u5f62<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>reshape<\/code>\u65b9\u6cd5\u6539\u53d8\u77e9\u9635\u7684\u5f62\u72b6\uff0c\u4f46\u9700\u8981\u786e\u4fdd\u603b\u5143\u7d20\u6570\u91cf\u4e0d\u53d8\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c064x3x2x5\u77e9\u9635\u53d8\u5f62\u4e3a6x4x5\u77e9\u9635<\/p>\n<p>reshaped_matrix = matrix_4d.reshape(6, 4, 5)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>reshaped_matrix<\/code>\u5c06\u5305\u542b\u4e0e<code>matrix_4d<\/code>\u76f8\u540c\u7684\u5143\u7d20\uff0c\u4f46\u5f62\u72b6\u53d8\u4e3a<code>(6, 4, 5)<\/code>\u3002<\/p>\n<\/p>\n<p><h2>\u4e03\u3001\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u56db\u7ef4\u77e9\u9635<\/h2>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u56db\u7ef4\u77e9\u9635\u53ef\u4ee5\u7528\u4e8e\u8868\u793a\u591a\u7ef4\u6570\u636e\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><h3>1\u3001\u56fe\u50cf\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u5904\u7406\u9886\u57df\uff0c\u56db\u7ef4\u77e9\u9635\u901a\u5e38\u7528\u4e8e\u8868\u793a\u4e00\u7ec4\u56fe\u50cf\u3002\u6bcf\u4e2a\u56fe\u50cf\u53ef\u4ee5\u7528\u4e00\u4e2a\u4e09\u7ef4\u77e9\u9635\u8868\u793a\uff0c\u5176\u4e2d\u7b2c\u4e00\u7ef4\u662f\u901a\u9053\u6570\uff08\u4f8b\u5982RGB\u56fe\u50cf\u6709\u4e09\u4e2a\u901a\u9053\uff09\uff0c\u7b2c\u4e8c\u7ef4\u548c\u7b2c\u4e09\u7ef4\u5206\u522b\u662f\u56fe\u50cf\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002\u5c06\u591a\u5f20\u56fe\u50cf\u5806\u53e0\u8d77\u6765\uff0c\u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5305\u542b10\u5f2064x64 RGB\u56fe\u50cf\u7684\u56db\u7ef4\u77e9\u9635<\/p>\n<p>images = np.random.rand(10, 64, 64, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u89c6\u9891\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u89c6\u9891\u5904\u7406\u4e2d\uff0c\u56db\u7ef4\u77e9\u9635\u53ef\u4ee5\u7528\u4e8e\u8868\u793a\u4e00\u6bb5\u89c6\u9891\u3002\u89c6\u9891\u53ef\u4ee5\u770b\u4f5c\u662f\u7531\u591a\u5e27\u56fe\u50cf\u7ec4\u6210\uff0c\u6bcf\u5e27\u56fe\u50cf\u7528\u4e00\u4e2a\u4e09\u7ef4\u77e9\u9635\u8868\u793a\uff0c\u5c06\u6240\u6709\u5e27\u5806\u53e0\u8d77\u6765\u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5305\u542b100\u5e2764x64 RGB\u56fe\u50cf\u7684\u89c6\u9891\u7684\u56db\u7ef4\u77e9\u9635<\/p>\n<p>video = np.random.rand(100, 64, 64, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u79d1\u5b66\u8ba1\u7b97<\/h3>\n<\/p>\n<p><p>\u5728\u79d1\u5b66\u8ba1\u7b97\u9886\u57df\uff0c\u56db\u7ef4\u77e9\u9635\u53ef\u4ee5\u7528\u4e8e\u8868\u793a\u590d\u6742\u7684\u6570\u636e\u96c6\uff0c\u4f8b\u5982\u6c14\u8c61\u6570\u636e\u3002\u6bcf\u4e2a\u7ef4\u5ea6\u53ef\u4ee5\u8868\u793a\u4e0d\u540c\u7684\u7269\u7406\u91cf\uff0c\u4f8b\u5982\u65f6\u95f4\u3001\u7ecf\u5ea6\u3001\u7eac\u5ea6\u548c\u9ad8\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u65f6\u95f4\u3001\u7ecf\u5ea6\u3001\u7eac\u5ea6\u548c\u9ad8\u5ea6\u7684\u6c14\u8c61\u6570\u636e\u7684\u56db\u7ef4\u77e9\u9635<\/p>\n<p>weather_data = np.random.rand(24, 180, 360, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>weather_data<\/code>\u662f\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\uff0c\u5f62\u72b6\u4e3a<code>(24, 180, 360, 10)<\/code>\uff0c\u5206\u522b\u8868\u793a24\u4e2a\u65f6\u95f4\u70b9\u3001180\u4e2a\u7ecf\u5ea6\u70b9\u3001360\u4e2a\u7eac\u5ea6\u70b9\u548c10\u4e2a\u9ad8\u5ea6\u5c42\u7684\u6c14\u8c61\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u516b\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4f7f\u7528NumPy\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u548c\u64cd\u4f5c\u56db\u7ef4\u77e9\u9635\u3002\u901a\u8fc7\u4f7f\u7528<code>numpy.zeros<\/code>\u3001<code>numpy.ones<\/code>\u3001<code>numpy.random<\/code>\u7b49\u51fd\u6570\uff0c\u53ef\u4ee5\u5feb\u901f\u521d\u59cb\u5316\u56db\u7ef4\u77e9\u9635\u3002\u521b\u5efa\u56db\u7ef4\u77e9\u9635\u540e\uff0c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u5305\u62ec\u8bbf\u95ee\u3001\u4fee\u6539\u3001\u5207\u7247\u3001\u77e9\u9635\u8fd0\u7b97\u548c\u53d8\u5f62\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u56db\u7ef4\u77e9\u9635\u5e7f\u6cdb\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u3001\u89c6\u9891\u5904\u7406\u548c\u79d1\u5b66\u8ba1\u7b97\u7b49\u9886\u57df\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u5904\u7406\u591a\u7ef4\u6570\u636e\uff0c\u5e76\u5e94\u7528\u5230\u5404\u79cd\u5b9e\u9645\u95ee\u9898\u4e2d\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u7406\u89e3\u548c\u4f7f\u7528\u56db\u7ef4\u77e9\u9635\u6709\u6240\u5e2e\u52a9\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\u56db\u7ef4\u77e9\u9635\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u521b\u5efa\u56db\u7ef4\u77e9\u9635\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7<code>pip install numpy<\/code>\u547d\u4ee4\u5b89\u88c5\u3002\u521b\u5efa\u56db\u7ef4\u77e9\u9635\u7684\u57fa\u672c\u6b65\u9aa4\u662f\u4f7f\u7528<code>numpy.zeros()<\/code>\u3001<code>numpy.ones()<\/code>\u6216<code>numpy.empty()<\/code>\u7b49\u51fd\u6570\u6765\u5b9a\u4e49\u77e9\u9635\u7684\u5f62\u72b6\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>numpy.zeros((2, 3, 4, 5))<\/code>\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5f62\u72b6\u4e3a2x3x4x5\u7684\u56db\u7ef4\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u521d\u59cb\u5316\u4e3a\u96f6\u3002<\/p>\n<p><strong>\u56db\u7ef4\u77e9\u9635\u7684\u5b9e\u9645\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u56db\u7ef4\u77e9\u9635\u5728\u8bb8\u591a\u9886\u57df\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f8b\u5982\uff0c\u5728\u8ba1\u7b97\u673a\u89c6\u89c9\u4e2d\uff0c\u56db\u7ef4\u77e9\u9635\u53ef\u4ee5\u7528\u6765\u8868\u793a\u89c6\u9891\u6570\u636e\uff0c\u5176\u4e2d\u4e24\u4e2a\u7ef4\u5ea6\u4ee3\u8868\u89c6\u9891\u5e27\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\uff0c\u7b2c\u4e09\u4e2a\u7ef4\u5ea6\u4ee3\u8868\u65f6\u95f4\u5e8f\u5217\uff0c\u7b2c\u56db\u4e2a\u7ef4\u5ea6\u5219\u4ee3\u8868\u989c\u8272\u901a\u9053\u3002\u5728\u6df1\u5ea6\u5b66\u4e60\u4e2d\uff0c\u56db\u7ef4\u77e9\u9635\u5e38\u7528\u4e8e\u8868\u793a\u6279\u91cf\u56fe\u50cf\u6570\u636e\uff0c\u65b9\u4fbf\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\u3002<\/p>\n<p><strong>\u5982\u4f55\u5bf9\u56db\u7ef4\u77e9\u9635\u8fdb\u884c\u64cd\u4f5c\u548c\u7d22\u5f15\uff1f<\/strong><br \/>\u5bf9\u56db\u7ef4\u77e9\u9635\u7684\u64cd\u4f5c\u4e0e\u4e00\u7ef4\u3001\u4e8c\u7ef4\u548c\u4e09\u7ef4\u77e9\u9635\u76f8\u4f3c\u3002\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u6765\u8bbf\u95ee\u7279\u5b9a\u7684\u5143\u7d20\u6216\u5207\u7247\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7<code>array[i, j, k, l]<\/code>\u7684\u65b9\u5f0f\u83b7\u53d6\u56db\u7ef4\u77e9\u9635\u4e2d\u7b2ci\u4e2a\u3001j\u4e2a\u3001k\u4e2a\u548cl\u4e2a\u5143\u7d20\u7684\u503c\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u64cd\u4f5c\u6765\u83b7\u53d6\u67d0\u4e00\u7ef4\u5ea6\u7684\u6240\u6709\u6570\u636e\uff0c\u6bd4\u5982<code>array[:, :, 0, :]<\/code>\u5c06\u8fd4\u56de\u6240\u6709\u7684\u7b2c\u4e00\u7ef4\u3001\u7b2c\u4e8c\u7ef4\u548c\u7b2c\u56db\u7ef4\u6570\u636e\uff0c\u540c\u65f6\u56fa\u5b9a\u7b2c\u4e09\u7ef4\u4e3a0\u3002\u8fd9\u79cd\u7075\u6d3b\u7684\u7d22\u5f15\u65b9\u5f0f\u8ba9\u6570\u636e\u5904\u7406\u66f4\u4e3a\u9ad8\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u56db\u7ef4\u77e9\u9635\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528NumPy\u5e93\u3002 NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5e93\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u5927\u578b\u591a\u7ef4\u6570 [&hellip;]","protected":false},"author":3,"featured_media":1124491,"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\/1124486"}],"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=1124486"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124486\/revisions"}],"predecessor-version":[{"id":1124493,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124486\/revisions\/1124493"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1124491"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1124486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1124486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1124486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}