{"id":1118275,"date":"2025-01-08T18:33:54","date_gmt":"2025-01-08T10:33:54","guid":{"rendered":""},"modified":"2025-01-08T18:33:57","modified_gmt":"2025-01-08T10:33:57","slug":"%e5%a6%82%e4%bd%95python%e4%b8%ad%e4%b8%80%e7%bb%b4%e6%95%b0%e7%bb%84%e7%9a%84%e8%bd%ac%e7%9f%a9%e9%98%b5-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1118275.html","title":{"rendered":"\u5982\u4f55python\u4e2d\u4e00\u7ef4\u6570\u7ec4\u7684\u8f6c\u77e9\u9635"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081824\/fc19ad41-a02a-40a4-973b-c851a83a2446.webp\" alt=\"\u5982\u4f55python\u4e2d\u4e00\u7ef4\u6570\u7ec4\u7684\u8f6c\u77e9\u9635\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u77e9\u9635\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u4f8b\u5982\u4f7f\u7528NumPy\u5e93\u4e2d\u7684reshape\u51fd\u6570\u3001\u5229\u7528\u5217\u8868\u751f\u6210\u5f0f\u548c\u5185\u7f6e\u51fd\u6570\u7b49\u3002\u6700\u5e38\u89c1\u548c\u63a8\u8350\u7684\u65b9\u6cd5\u662f\u4f7f\u7528NumPy\u5e93\uff0c\u56e0\u4e3a\u5b83\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4f7f\u7528NumPy\u5e93<\/h3>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u7ec4\u5904\u7406\u80fd\u529b\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528NumPy\u7684reshape\u51fd\u6570\u8f7b\u677e\u5730\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><p><strong>\u5b89\u88c5NumPy\u5e93\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/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, 6])<\/p>\n<h2><strong>\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a2x3\u77e9\u9635<\/strong><\/h2>\n<p>matrix_2x3 = array_1d.reshape(2, 3)<\/p>\n<p>print(matrix_2x3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>NumPy\u5e93\u4e2d\u7684reshape\u51fd\u6570<\/h3>\n<\/p>\n<p><p><strong>reshape\u51fd\u6570\u7684\u4f7f\u7528\uff1a<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u7684reshape\u51fd\u6570\u7528\u4e8e\u5728\u4e0d\u6539\u53d8\u6570\u636e\u7684\u60c5\u51b5\u4e0b\u6539\u53d8\u6570\u7ec4\u7684\u5f62\u72b6\u3002\u5b83\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numpy.reshape(a, newshape)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>a<\/strong>\uff1a\u8981\u8f6c\u6362\u7684\u6570\u7ec4\u3002<\/li>\n<li><strong>newshape<\/strong>\uff1a\u65b0\u5f62\u72b6\uff0c\u53ef\u4ee5\u662f\u4e00\u4e2a\u6574\u6570\u6216\u4e00\u4e2a\u5143\u7ec4\u3002\u5982\u679c\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u65b0\u6570\u7ec4\u7684\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u5176\u4f59\u7ef4\u5ea6\u4f1a\u81ea\u52a8\u8ba1\u7b97\u3002\u5982\u679c\u662f\u4e00\u4e2a\u5143\u7ec4\uff0c\u5219\u8868\u793a\u65b0\u6570\u7ec4\u7684\u5404\u7ef4\u5ea6\u3002<\/li>\n<\/ul>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/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, 6, 7, 8, 9, 10, 11, 12])<\/p>\n<h2><strong>\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a3x4\u77e9\u9635<\/strong><\/h2>\n<p>matrix_3x4 = array_1d.reshape(3, 4)<\/p>\n<p>print(matrix_3x4)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528\u5217\u8868\u751f\u6210\u5f0f<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e00\u4e9b\u7b80\u5355\u7684\u8f6c\u6362\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5217\u8868\u751f\u6210\u5f0f\u6765\u624b\u52a8\u5b9e\u73b0\u4e00\u7ef4\u6570\u7ec4\u5230\u77e9\u9635\u7684\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4<\/p>\n<p>array_1d = [1, 2, 3, 4, 5, 6]<\/p>\n<h2><strong>\u8f6c\u6362\u4e3a2x3\u77e9\u9635<\/strong><\/h2>\n<p>rows = 2<\/p>\n<p>cols = 3<\/p>\n<p>matrix_2x3 = [array_1d[i * cols:(i + 1) * cols] for i in range(rows)]<\/p>\n<p>print(matrix_2x3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/h3>\n<\/p>\n<p><p>Python\u7684\u5185\u7f6e\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u4e8e\u6570\u7ec4\u7684\u8f6c\u6362\u3002\u867d\u7136\u4e0d\u5982NumPy\u65b9\u4fbf\uff0c\u4f46\u4e5f\u80fd\u5b8c\u6210\u57fa\u672c\u7684\u8f6c\u6362\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4<\/p>\n<p>array_1d = [1, 2, 3, 4, 5, 6]<\/p>\n<h2><strong>\u5b9a\u4e49\u77e9\u9635\u7684\u884c\u6570\u548c\u5217\u6570<\/strong><\/h2>\n<p>rows, cols = 2, 3<\/p>\n<h2><strong>\u521d\u59cb\u5316\u77e9\u9635<\/strong><\/h2>\n<p>matrix = []<\/p>\n<p>for i in range(rows):<\/p>\n<p>    row = []<\/p>\n<p>    for j in range(cols):<\/p>\n<p>        row.append(array_1d[i * cols + j])<\/p>\n<p>    matrix.append(row)<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u77e9\u9635\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528NumPy\u5e93\u3001\u5217\u8868\u751f\u6210\u5f0f\u548c\u5185\u7f6e\u51fd\u6570\u3002<strong>\u4f7f\u7528NumPy\u5e93\u662f\u6700\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528<\/strong>\u3002\u901a\u8fc7reshape\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u4efb\u4f55\u5f62\u72b6\u7684\u77e9\u9635\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u751f\u6210\u5f0f\u548c\u5185\u7f6e\u51fd\u6570\u6765\u624b\u52a8\u5b9e\u73b0\u8f6c\u6362\uff0c\u4f46\u8fd9\u4e9b\u65b9\u6cd5\u5728\u5904\u7406\u590d\u6742\u7684\u6570\u7ec4\u65f6\u53ef\u80fd\u4e0d\u5982NumPy\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<p><h3>\u6df1\u5165\u7406\u89e3NumPy\u7684reshape<\/h3>\n<\/p>\n<p><p><strong>NumPy\u7684reshape\u51fd\u6570\u4e0d\u4ec5\u4ec5\u9650\u4e8e\u7b80\u5355\u7684\u8f6c\u6362\uff0c\u8fd8\u53ef\u4ee5\u5728\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u65f6\u53d1\u6325\u66f4\u5927\u7684\u4f5c\u7528\u3002<\/strong>\u4e86\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u548c\u5e38\u89c1\u7528\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u591a\u7ef4\u6570\u7ec4\u7684\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u591a\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e0d\u540c\u7684\u5f62\u72b6\u3002reshape\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u4e0d\u6539\u53d8\u6570\u636e\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\u5b8c\u6210\u8fd9\u79cd\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a3x4\u7684\u77e9\u9635<\/strong><\/h2>\n<p>matrix_3x4 = np.array([[1, 2, 3, 4],<\/p>\n<p>                       [5, 6, 7, 8],<\/p>\n<p>                       [9, 10, 11, 12]])<\/p>\n<h2><strong>\u5c063x4\u77e9\u9635\u8f6c\u6362\u4e3a2x6\u77e9\u9635<\/strong><\/h2>\n<p>matrix_2x6 = matrix_3x4.reshape(2, 6)<\/p>\n<p>print(matrix_2x6)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>reshape\u4e2d\u7684-1\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528reshape\u51fd\u6570\u65f6\uff0c<strong>-1\u53c2\u6570\u53ef\u4ee5\u81ea\u52a8\u8ba1\u7b97\u67d0\u4e00\u4e2a\u7ef4\u5ea6\u7684\u5927\u5c0f<\/strong>\u3002\u8fd9\u5728\u6211\u4eec\u53ea\u5173\u5fc3\u67d0\u4e00\u4e2a\u7ef4\u5ea6\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/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, 6, 7, 8, 9, 10, 11, 12])<\/p>\n<h2><strong>\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a3x4\u77e9\u9635<\/strong><\/h2>\n<p>matrix_3x4 = array_1d.reshape(3, -1)<\/p>\n<p>print(matrix_3x4)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u9ad8\u7ea7\u7528\u6cd5\uff1a\u5206\u5757\u4e0e\u5408\u5e76<\/h3>\n<\/p>\n<p><p>NumPy\u7684reshape\u51fd\u6570\u8fd8\u53ef\u4ee5\u914d\u5408\u5176\u4ed6\u51fd\u6570\uff0c\u5982vstack\u3001hstack\u7b49\uff0c\u5b9e\u73b0\u6570\u7ec4\u7684\u5206\u5757\u4e0e\u5408\u5e76\u64cd\u4f5c\u3002\u8fd9\u5728\u6570\u636e\u9884\u5904\u7406\u4e2d\u975e\u5e38\u5e38\u89c1\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/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, 6, 7, 8, 9, 10, 11, 12])<\/p>\n<h2><strong>\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a3x4\u77e9\u9635<\/strong><\/h2>\n<p>matrix_3x4 = array_1d.reshape(3, 4)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u6309\u884c\u5206\u5272\u4e3a\u4e24\u4e2a\u5b50\u77e9\u9635<\/strong><\/h2>\n<p>sub_matrix_1, sub_matrix_2 = np.vsplit(matrix_3x4, 2)<\/p>\n<p>print(sub_matrix_1)<\/p>\n<p>print(sub_matrix_2)<\/p>\n<h2><strong>\u5c06\u4e24\u4e2a\u5b50\u77e9\u9635\u5408\u5e76\u4e3a\u4e00\u4e2a\u77e9\u9635<\/strong><\/h2>\n<p>merged_matrix = np.vstack((sub_matrix_1, sub_matrix_2))<\/p>\n<p>print(merged_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>reshape\u7684\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528reshape\u51fd\u6570\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u603b\u91cf\u4e0d\u53d8<\/strong>\uff1areshape\u524d\u540e\u7684\u6570\u7ec4\u5143\u7d20\u603b\u6570\u5fc5\u987b\u76f8\u540c\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u3002<\/li>\n<li><strong>\u8fde\u7eed\u6570\u636e\u5b58\u50a8<\/strong>\uff1areshape\u64cd\u4f5c\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u89c6\u56fe\uff0c\u4e0d\u4f1a\u6539\u53d8\u539f\u59cb\u6570\u636e\uff0c\u4f46\u8981\u6c42\u6570\u7ec4\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u5b58\u50a8\u7684\u3002<\/li>\n<li><strong>\u9ad8\u7ef4\u6570\u7ec4<\/strong>\uff1a\u5bf9\u4e8e\u9ad8\u7ef4\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f9d\u6b21\u6307\u5b9a\u5404\u7ef4\u5ea6\u7684\u5927\u5c0f\u8fdb\u884c\u8f6c\u6362\u3002<\/li>\n<\/ol>\n<p><p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a4x3x2\u7684\u4e09\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array_3d = np.arange(24).reshape(4, 3, 2)<\/p>\n<h2><strong>\u5c06\u4e09\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a2x12\u7684\u4e8c\u7ef4\u6570\u7ec4<\/strong><\/h2>\n<p>array_2d = array_3d.reshape(2, 12)<\/p>\n<p>print(array_2d)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u638c\u63e1\u5982\u4f55\u5728Python\u4e2d\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u77e9\u9635\u662f\u6570\u636e\u5904\u7406\u4e2d\u7684\u57fa\u672c\u6280\u80fd\u3002<strong>NumPy\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5c24\u5176\u662freshape\u51fd\u6570\uff0c\u4f7f\u5f97\u8fd9\u79cd\u8f6c\u6362\u53d8\u5f97\u7b80\u5355\u9ad8\u6548\u3002<\/strong>\u901a\u8fc7\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u7075\u6d3b\u5730\u5904\u7406\u548c\u64cd\u4f5c\u6570\u636e\uff0c\u4ece\u800c\u66f4\u597d\u5730\u5b8c\u6210\u5404\u7c7b\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u77e9\u9635\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u8f7b\u677e\u5b9e\u73b0\u4e00\u7ef4\u6570\u7ec4\u5230\u77e9\u9635\u7684\u8f6c\u6362\u3002\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5NumPy\u5e93\uff08\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff09\u5e76\u5bfc\u5165\u5b83\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528<code>reshape<\/code>\u65b9\u6cd5\u6765\u8c03\u6574\u4e00\u7ef4\u6570\u7ec4\u7684\u5f62\u72b6\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u5c06\u4e00\u4e2a\u5305\u542b9\u4e2a\u5143\u7d20\u7684\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a3&#215;3\u7684\u77e9\u9635\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\narray_1d = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])\nmatrix_2d = array_1d.reshape(3, 3)\nprint(matrix_2d)\n<\/code><\/pre>\n<p><strong>\u5728\u8f6c\u6362\u65f6\u5982\u4f55\u5904\u7406\u4e0d\u540c\u5927\u5c0f\u7684\u4e00\u7ef4\u6570\u7ec4\uff1f<\/strong><br \/>\u5982\u679c\u4e00\u7ef4\u6570\u7ec4\u7684\u5927\u5c0f\u4e0d\u9002\u5408\u8f6c\u6362\u4e3a\u6240\u9700\u7684\u77e9\u9635\u5f62\u72b6\uff0cNumPy\u4f1a\u629b\u51fa\u4e00\u4e2a\u9519\u8bef\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u786e\u4fdd\u6570\u7ec4\u7684\u5143\u7d20\u603b\u6570\u80fd\u591f\u88ab\u6240\u9700\u7684\u884c\u6570\u548c\u5217\u6570\u6574\u9664\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u7ef4\u6570\u7ec4\u670910\u4e2a\u5143\u7d20\uff0c\u800c\u60f3\u8981\u5c06\u5176\u8f6c\u6362\u4e3a3&#215;3\u7684\u77e9\u9635\uff0c\u5219\u5fc5\u987b\u5148\u8c03\u6574\u6570\u7ec4\u7684\u5927\u5c0f\u6216\u9009\u62e9\u5408\u9002\u7684\u77e9\u9635\u5f62\u72b6\uff0c\u4f8b\u59822&#215;5\u62165&#215;2\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u5176\u4ed6\u5e93\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u4e3a\u77e9\u9635\uff1f<\/strong><br \/>\u9664\u4e86NumPy\u4e4b\u5916\uff0c\u4f7f\u7528Pandas\u5e93\u4e5f\u662f\u4e00\u79cd\u9009\u62e9\u3002Pandas\u7684DataFrame\u5bf9\u8c61\u53ef\u4ee5\u5904\u7406\u77e9\u9635\u6570\u636e\u3002\u53ef\u4ee5\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3aSeries\uff0c\u7136\u540e\u518d\u8f6c\u6362\u4e3aDataFrame\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\narray_1d = [1, 2, 3, 4, 5, 6, 7, 8, 9]\ndf = pd.DataFrame(array_1d).values.reshape(3, 3)\nprint(df)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4e5f\u63d0\u4f9b\u4e86\u7075\u6d3b\u6027\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u6570\u636e\u96c6\u65f6\uff0c\u9002\u5408\u9700\u8981\u6570\u636e\u5206\u6790\u7684\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5c06\u4e00\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u77e9\u9635\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u4f8b\u5982\u4f7f\u7528NumPy\u5e93\u4e2d\u7684reshape\u51fd\u6570\u3001\u5229\u7528\u5217\u8868\u751f [&hellip;]","protected":false},"author":3,"featured_media":1118280,"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\/1118275"}],"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=1118275"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1118275\/revisions"}],"predecessor-version":[{"id":1118283,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1118275\/revisions\/1118283"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1118280"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1118275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1118275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1118275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}