{"id":978520,"date":"2024-12-27T06:38:31","date_gmt":"2024-12-26T22:38:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/978520.html"},"modified":"2024-12-27T06:38:33","modified_gmt":"2024-12-26T22:38:33","slug":"%e7%94%a8python%e5%a6%82%e4%bd%95%e5%bb%ba%e7%ab%8b%e7%9f%a9%e9%98%b5","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/978520.html","title":{"rendered":"\u7528python\u5982\u4f55\u5efa\u7acb\u77e9\u9635"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24203458\/86630867-a13a-419d-9de3-e3502eb5e9aa.webp\" alt=\"\u7528python\u5982\u4f55\u5efa\u7acb\u77e9\u9635\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<br \/><strong>\u4f7f\u7528Python\u5efa\u7acb\u77e9\u9635\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ecNumPy\u5e93\u3001\u5217\u8868\u5d4c\u5957\u3001Pandas\u5e93\u3002NumPy\u5e93\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\u652f\u6301\u3002<\/strong> \u5728\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9886\u57df\uff0cNumPy\u5e93\u56e0\u5176\u9ad8\u6548\u6027\u548c\u7b80\u6d01\u6027\u800c\u5907\u53d7\u63a8\u5d07\u3002\u901a\u8fc7NumPy\u5e93\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u3001\u64cd\u4f5c\u548c\u8ba1\u7b97\u77e9\u9635\u3002\u6b64\u5916\uff0cPandas\u5e93\u4e5f\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u5b83\u80fd\u591f\u4ee5\u6570\u636e\u6846\u7684\u5f62\u5f0f\u5904\u7406\u4e8c\u7ef4\u6570\u636e\uff0c\u975e\u5e38\u9002\u5408\u5904\u7406\u5e26\u6709\u6807\u7b7e\u7684\u6570\u636e\u96c6\u3002\u867d\u7136\u5217\u8868\u5d4c\u5957\u662f\u4e00\u79cd\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u4f46\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\u6548\u7387\u8f83\u4f4e\uff0c\u56e0\u6b64\u8f83\u5c11\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528NUMPY\u5e93\u521b\u5efa\u77e9\u9635<\/p>\n<\/p>\n<p><p>NumPy\uff08Numerical Python\uff09\u662fPython\u4e2d\u6700\u6d41\u884c\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u3002\u4f7f\u7528NumPy\u5e93\u521b\u5efa\u77e9\u9635\u662f\u975e\u5e38\u9ad8\u6548\u7684\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u5bfc\u5165NumPy<\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528NumPy\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\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<p><p>\u7136\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165NumPy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528numpy.array\u521b\u5efa\u77e9\u9635<\/li>\n<\/ol>\n<p><p>NumPy\u63d0\u4f9b\u4e86<code>array()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u5217\u8868\u6216\u5217\u8868\u7684\u5217\u8868\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u4ece\u800c\u521b\u5efa\u77e9\u9635\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u4f7f\u7528numpy.zeros\u548cnumpy.ones\u521b\u5efa\u77e9\u9635<\/li>\n<\/ol>\n<p><p>NumPy\u8fd8\u63d0\u4f9b\u4e86<code>zeros()<\/code>\u548c<code>ones()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u521b\u5efa\u5143\u7d20\u5168\u4e3a0\u62161\u7684\u77e9\u9635\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">zero_matrix = np.zeros((3, 3))<\/p>\n<p>one_matrix = np.ones((3, 3))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e9b\u51fd\u6570\u9700\u8981\u4f20\u9012\u4e00\u4e2a\u5143\u7ec4\u4f5c\u4e3a\u53c2\u6570\uff0c\u6307\u5b9a\u77e9\u9635\u7684\u5f62\u72b6\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li>\u4f7f\u7528numpy.eye\u521b\u5efa\u5355\u4f4d\u77e9\u9635<\/li>\n<\/ol>\n<p><p><code>eye()<\/code>\u51fd\u6570\u7528\u4e8e\u521b\u5efa\u5355\u4f4d\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">identity_matrix = np.eye(3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a3&#215;3\u7684\u5355\u4f4d\u77e9\u9635\uff0c\u5bf9\u89d2\u7ebf\u5143\u7d20\u4e3a1\uff0c\u5176\u4f59\u5143\u7d20\u4e3a0\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5217\u8868\u5d4c\u5957\u521b\u5efa\u77e9\u9635<\/p>\n<\/p>\n<p><p>Python\u7684\u5217\u8868\u662f\u4e00\u79cd\u975e\u5e38\u7075\u6d3b\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u7b80\u5355\u7684\u77e9\u9635\u7ed3\u6784\u3002<\/p>\n<\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u5217\u8868\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5d4c\u5957\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u77e9\u9635\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>matrix<\/code>\u662f\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u8bbf\u95ee\u548c\u4fee\u6539\u5217\u8868\u77e9\u9635\u4e2d\u7684\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u548c\u4fee\u6539\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = matrix[1][2]  # \u83b7\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20<\/p>\n<p>matrix[1][2] = 10  # \u5c06\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20\u4fee\u6539\u4e3a10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528PANDAS\u5e93\u521b\u5efa\u77e9\u9635<\/p>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u8868\u683c\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u5bfc\u5165Pandas<\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86Pandas\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u811a\u672c\u4e2d\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528DataFrame\u521b\u5efa\u77e9\u9635<\/li>\n<\/ol>\n<p><p>Pandas\u4e2d\u7684DataFrame\u662f\u4e00\u79cd\u4e8c\u7ef4\u6570\u636e\u7ed3\u6784\uff0c\u7c7b\u4f3c\u4e8e\u7535\u5b50\u8868\u683c\uff0c\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u77e9\u9635\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {&#39;A&#39;: [1, 4, 7], &#39;B&#39;: [2, 5, 8], &#39;C&#39;: [3, 6, 9]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e09\u5217\u7684DataFrame\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u8bbf\u95ee\u548c\u4fee\u6539DataFrame\u4e2d\u7684\u5143\u7d20<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5217\u540d\u548c\u7d22\u5f15\uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u548c\u4fee\u6539DataFrame\u4e2d\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = df.loc[1, &#39;B&#39;]  # \u83b7\u53d6\u7b2c\u4e8c\u884cB\u5217\u7684\u5143\u7d20<\/p>\n<p>df.loc[1, &#39;B&#39;] = 10  # \u5c06\u7b2c\u4e8c\u884cB\u5217\u7684\u5143\u7d20\u4fee\u6539\u4e3a10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u77e9\u9635\u8fd0\u7b97\u548c\u64cd\u4f5c<\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u521b\u5efa\u4e86\u77e9\u9635\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u5404\u79cd\u8fd0\u7b97\u548c\u64cd\u4f5c\u3002NumPy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u51fd\u6570\u6765\u5904\u7406\u77e9\u9635\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<ol>\n<li>\u77e9\u9635\u52a0\u6cd5\u548c\u51cf\u6cd5<\/li>\n<\/ol>\n<p><p>NumPy\u53ef\u4ee5\u76f4\u63a5\u5bf9\u77e9\u9635\u8fdb\u884c\u52a0\u6cd5\u548c\u51cf\u6cd5\u8fd0\u7b97\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix1 = np.array([[1, 2], [3, 4]])<\/p>\n<p>matrix2 = np.array([[5, 6], [7, 8]])<\/p>\n<p>sum_matrix = matrix1 + matrix2<\/p>\n<p>diff_matrix = matrix1 - matrix2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u77e9\u9635\u4e58\u6cd5<\/li>\n<\/ol>\n<p><p>\u77e9\u9635\u4e58\u6cd5\u53ef\u4ee5\u4f7f\u7528<code>dot()<\/code>\u51fd\u6570\u6216<code>@<\/code>\u8fd0\u7b97\u7b26\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">product_matrix = np.dot(matrix1, matrix2)  # \u4f7f\u7528dot\u51fd\u6570<\/p>\n<p>product_matrix = matrix1 @ matrix2  # \u4f7f\u7528@\u8fd0\u7b97\u7b26<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u8f6c\u7f6e\u77e9\u9635<\/li>\n<\/ol>\n<p><p>\u8f6c\u7f6e\u77e9\u9635\u53ef\u4ee5\u4f7f\u7528<code>transpose()<\/code>\u6216<code>.T<\/code>\u5c5e\u6027\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">transposed_matrix = matrix1.T<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u77e9\u9635\u7684\u5e94\u7528\u573a\u666f<\/p>\n<\/p>\n<p><p>\u77e9\u9635\u5728\u79d1\u5b66\u8ba1\u7b97\u3001\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u4e2d\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li>\u7ebf\u6027\u4ee3\u6570<\/li>\n<\/ol>\n<p><p>\u77e9\u9635\u662f\u7ebf\u6027\u4ee3\u6570\u7684\u6838\u5fc3\uff0c\u53ef\u4ee5\u7528\u4e8e\u89e3\u7ebf\u6027\u65b9\u7a0b\u7ec4\u3001\u8ba1\u7b97\u884c\u5217\u5f0f\u3001\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u7b49\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u6570\u636e\u5206\u6790<\/li>\n<\/ol>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0c\u77e9\u9635\u7528\u4e8e\u5b58\u50a8\u548c\u5904\u7406\u6570\u636e\u96c6\u3002\u901a\u8fc7\u77e9\u9635\u8fd0\u7b97\uff0c\u53ef\u4ee5\u8f7b\u677e\u8fdb\u884c\u6570\u636e\u7684\u52a0\u6743\u3001\u5f52\u4e00\u5316\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u673a\u5668\u5b66\u4e60<\/li>\n<\/ol>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u7279\u5f81\u77e9\u9635\u662f\u6a21\u578b\u8bad\u7ec3\u548c\u9884\u6d4b\u7684\u91cd\u8981\u57fa\u7840\u3002\u77e9\u9635\u8fd0\u7b97\u53ef\u4ee5\u52a0\u901f\u6a21\u578b\u7684\u8bad\u7ec3\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u6027\u80fd\u4f18\u5316\u548c\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u6027\u80fd\u4f18\u5316\u662f\u4e00\u4e2a\u91cd\u8981\u8003\u8651\u56e0\u7d20\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528NumPy\u7684\u5411\u91cf\u5316\u8fd0\u7b97<\/li>\n<\/ol>\n<p><p>NumPy\u7684\u5411\u91cf\u5316\u8fd0\u7b97\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\uff0c\u5c3d\u91cf\u907f\u514d\u4f7f\u7528for\u5faa\u73af\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u5408\u7406\u4f7f\u7528\u5185\u5b58<\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u8d85\u5927\u578b\u77e9\u9635\uff0c\u786e\u4fdd\u6709\u8db3\u591f\u7684\u5185\u5b58\u8fdb\u884c\u8ba1\u7b97\u3002\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7a00\u758f\u77e9\u9635\u6765\u8282\u7701\u5185\u5b58\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u6ce8\u610f\u6570\u636e\u7c7b\u578b<\/li>\n<\/ol>\n<p><p>\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u548c\u8282\u7701\u5185\u5b58\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>float32<\/code>\u800c\u4e0d\u662f<code>float64<\/code>\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3\u800c\u8a00\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u521b\u5efa\u548c\u64cd\u4f5c\u77e9\u9635\u7684\u65b9\u5f0f\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u3002\u5728\u6570\u636e\u79d1\u5b66\u3001\u673a\u5668\u5b66\u4e60\u548c\u79d1\u5b66\u8ba1\u7b97\u9886\u57df\uff0c\u719f\u7ec3\u638c\u63e1\u77e9\u9635\u64cd\u4f5c\u662f\u81f3\u5173\u91cd\u8981\u7684\u6280\u80fd\u3002\u901a\u8fc7\u4e0d\u65ad\u5b9e\u8df5\u548c\u63a2\u7d22\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u6280\u672f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u7528Python\u521b\u5efa\u4e00\u4e2a\u7a7a\u77e9\u9635\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u521b\u5efa\u4e00\u4e2a\u7a7a\u77e9\u9635\u3002\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5NumPy\u5e93\uff08\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff09\uff0c\u7136\u540e\u53ef\u4ee5\u4f7f\u7528<code>numpy.empty()<\/code>\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np\nempty_matrix = np.empty((3, 3))  # \u521b\u5efa\u4e00\u4e2a3x3\u7684\u7a7a\u77e9\u9635\nprint(empty_matrix)\n<\/code><\/pre>\n<p>\u6b64\u4ee3\u7801\u5c06\u751f\u6210\u4e00\u4e2a3\u884c3\u5217\u7684\u77e9\u9635\uff0c\u77e9\u9635\u4e2d\u7684\u503c\u5c06\u662f\u672a\u521d\u59cb\u5316\u7684\u968f\u673a\u503c\u3002<\/p>\n<p><strong>Python\u4e2d\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u7279\u5b9a\u6570\u503c\u7684\u77e9\u9635\uff1f<\/strong><br \/>\u4f7f\u7528NumPy\u5e93\u7684<code>numpy.full()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6240\u6709\u5143\u7d20\u90fd\u4e3a\u7279\u5b9a\u503c\u7684\u77e9\u9635\u3002\u793a\u4f8b\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np\nfilled_matrix = np.full((2, 4), 7)  # \u521b\u5efa\u4e00\u4e2a2x4\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u4e3a7\nprint(filled_matrix)\n<\/code><\/pre>\n<p>\u8fd0\u884c\u6b64\u4ee3\u7801\u5c06\u8f93\u51fa\u4e00\u4e2a\u5305\u542b7\u76842\u884c4\u5217\u7684\u77e9\u9635\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u64cd\u4f5c\u77e9\u9635\uff1f<\/strong><br \/>\u64cd\u4f5c\u77e9\u9635\u53ef\u4ee5\u901a\u8fc7NumPy\u5e93\u7684\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\u3002\u5e38\u89c1\u7684\u64cd\u4f5c\u5305\u62ec\u77e9\u9635\u52a0\u6cd5\u3001\u4e58\u6cd5\u548c\u8f6c\u7f6e\u7b49\u3002\u4f8b\u5982\uff0c\u4e24\u4e2a\u77e9\u9635\u76f8\u52a0\u53ef\u4ee5\u4f7f\u7528<code>+<\/code>\u8fd0\u7b97\u7b26\uff0c\u800c\u8f6c\u7f6e\u5219\u53ef\u4ee5\u901a\u8fc7<code>numpy.transpose()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np\nmatrix_a = np.array([[1, 2], [3, 4]])\nmatrix_b = np.array([[5, 6], [7, 8]])\nsum_matrix = matrix_a + matrix_b  # \u77e9\u9635\u76f8\u52a0\ntransposed_matrix = np.transpose(matrix_a)  # \u77e9\u9635\u8f6c\u7f6e\nprint(sum_matrix)\nprint(transposed_matrix)\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u5bf9\u77e9\u9635\u8fdb\u884c\u57fa\u672c\u7684\u52a0\u6cd5\u548c\u8f6c\u7f6e\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a\u4f7f\u7528Python\u5efa\u7acb\u77e9\u9635\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ecNumPy\u5e93\u3001\u5217\u8868\u5d4c\u5957\u3001Pandas\u5e93\u3002NumPy\u5e93\u662f [&hellip;]","protected":false},"author":3,"featured_media":978529,"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\/978520"}],"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=978520"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/978520\/revisions"}],"predecessor-version":[{"id":978532,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/978520\/revisions\/978532"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/978529"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=978520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=978520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=978520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}