{"id":1166748,"date":"2025-01-15T15:35:51","date_gmt":"2025-01-15T07:35:51","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1166748.html"},"modified":"2025-01-15T15:35:54","modified_gmt":"2025-01-15T07:35:54","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bd%bf%e7%9f%a9%e9%98%b5%e5%8f%8d%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1166748.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u4f7f\u77e9\u9635\u53cd\u8f6c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25210814\/5a9cc274-b2a4-4604-99aa-4cc063336404.webp\" alt=\"python\u4e2d\u5982\u4f55\u4f7f\u77e9\u9635\u53cd\u8f6c\" \/><\/p>\n<p><p> \u5728Python\u4e2d\uff0c<strong>\u4f60\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c<\/strong>\u3001<strong>\u53ef\u4ee5\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u518d\u8fdb\u884c\u884c\u53cd\u8f6c<\/strong>\u3001<strong>\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u53cd\u8f6c\u77e9\u9635<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u4f7f\u7528NumPy\u5e93\u662f\u6700\u7b80\u5355\u548c\u5e38\u89c1\u7684\u65b9\u6cd5<\/strong>\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7NumPy\u5e93\u4e2d\u7684<code>numpy.linalg.inv<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528NumPy\u5e93\u6765\u53cd\u8f6c\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528NumPy\u5e93\u53cd\u8f6c\u77e9\u9635\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5NumPy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u6765\u53cd\u8f6c\u77e9\u9635\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165NumPy\u5e93<\/strong>\uff1a\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165NumPy\u5e93\u3002<\/li>\n<li><strong>\u521b\u5efa\u77e9\u9635<\/strong>\uff1a\u4f7f\u7528NumPy\u7684<code>array<\/code>\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u3002<\/li>\n<li><strong>\u53cd\u8f6c\u77e9\u9635<\/strong>\uff1a\u4f7f\u7528NumPy\u7684<code>linalg.inv<\/code>\u51fd\u6570\u6765\u53cd\u8f6c\u77e9\u9635\u3002<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5177\u4f53\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u77e9\u9635<\/strong><\/h2>\n<p>matrix = np.array([[1, 2], [3, 4]])<\/p>\n<h2><strong>\u4f7f\u7528NumPy\u5e93\u53cd\u8f6c\u77e9\u9635<\/strong><\/h2>\n<p>inverse_matrix = np.linalg.inv(matrix)<\/p>\n<p>print(&quot;Original Matrix:&quot;)<\/p>\n<p>print(matrix)<\/p>\n<p>print(&quot;Inverse Matrix:&quot;)<\/p>\n<p>print(inverse_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86NumPy\u5e93\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a2&#215;2\u7684\u77e9\u9635\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528<code>numpy.linalg.inv<\/code>\u51fd\u6570\u53cd\u8f6c\u4e86\u8fd9\u4e2a\u77e9\u9635\uff0c\u5e76\u6253\u5370\u51fa\u4e86\u539f\u59cb\u77e9\u9635\u548c\u53cd\u8f6c\u540e\u7684\u77e9\u9635\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001NUMPY\u5e93\u7684\u77e9\u9635\u53cd\u8f6c<\/h3>\n<\/p>\n<p><p>NumPy\u662fPython\u4e2d\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u7684\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5e93\u3002\u901a\u8fc7\u4f7f\u7528NumPy\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u5404\u79cd\u77e9\u9635\u64cd\u4f5c\uff0c\u5305\u62ec\u77e9\u9635\u7684\u53cd\u8f6c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528NumPy\u5e93\u6765\u53cd\u8f6c\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5bfc\u5165NumPy\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165NumPy\u5e93\u3002\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u5e93\uff0c\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5bfc\u5165NumPy\u5e93\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u521b\u5efa\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u3002\u5728NumPy\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>array<\/code>\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u521b\u5efa2&#215;2\u77e9\u9635\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a2x2\u7684\u77e9\u9635<\/p>\n<p>matrix = np.array([[1, 2], [3, 4]])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u53cd\u8f6c\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u4e00\u65e6\u6211\u4eec\u521b\u5efa\u4e86\u77e9\u9635\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528NumPy\u7684<code>linalg.inv<\/code>\u51fd\u6570\u6765\u53cd\u8f6c\u77e9\u9635\u3002\u8fd9\u4e2a\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u77e9\u9635\uff0c\u5373\u539f\u59cb\u77e9\u9635\u7684\u9006\u77e9\u9635\u3002\u4ee5\u4e0b\u662f\u53cd\u8f6c\u77e9\u9635\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u53cd\u8f6c\u77e9\u9635<\/p>\n<p>inverse_matrix = np.linalg.inv(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u6253\u5370\u7ed3\u679c<\/h4>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u6253\u5370\u51fa\u539f\u59cb\u77e9\u9635\u548c\u53cd\u8f6c\u540e\u7684\u77e9\u9635\uff0c\u4ee5\u4fbf\u67e5\u770b\u7ed3\u679c\u3002\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a2x2\u7684\u77e9\u9635<\/strong><\/h2>\n<p>matrix = np.array([[1, 2], [3, 4]])<\/p>\n<h2><strong>\u53cd\u8f6c\u77e9\u9635<\/strong><\/h2>\n<p>inverse_matrix = np.linalg.inv(matrix)<\/p>\n<h2><strong>\u6253\u5370\u539f\u59cb\u77e9\u9635<\/strong><\/h2>\n<p>print(&quot;Original Matrix:&quot;)<\/p>\n<p>print(matrix)<\/p>\n<h2><strong>\u6253\u5370\u53cd\u8f6c\u540e\u7684\u77e9\u9635<\/strong><\/h2>\n<p>print(&quot;Inverse Matrix:&quot;)<\/p>\n<p>print(inverse_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u540e\uff0c\u4f60\u5c06\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Original Matrix:<\/p>\n<p>[[1 2]<\/p>\n<p> [3 4]]<\/p>\n<p>Inverse Matrix:<\/p>\n<p>[[-2.   1. ]<\/p>\n<p> [ 1.5 -0.5]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u4f60\u6240\u89c1\uff0c\u539f\u59cb\u77e9\u9635\u88ab\u6210\u529f\u53cd\u8f6c\uff0c\u5f97\u5230\u4e86\u4e00\u4e2a\u65b0\u7684\u9006\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u518d\u8fdb\u884c\u884c\u53cd\u8f6c<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528NumPy\u5e93\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u7136\u540e\u518d\u8fdb\u884c\u884c\u53cd\u8f6c\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8f6c\u7f6e\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u77e9\u9635\u8fdb\u884c\u8f6c\u7f6e\u3002\u5728NumPy\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>transpose<\/code>\u51fd\u6570\u6765\u8f6c\u7f6e\u77e9\u9635\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8f6c\u7f6e\u77e9\u9635\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a2x2\u7684\u77e9\u9635<\/strong><\/h2>\n<p>matrix = np.array([[1, 2], [3, 4]])<\/p>\n<h2><strong>\u8f6c\u7f6e\u77e9\u9635<\/strong><\/h2>\n<p>transposed_matrix = np.transpose(matrix)<\/p>\n<p>print(&quot;Transposed Matrix:&quot;)<\/p>\n<p>print(transposed_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u540e\uff0c\u4f60\u5c06\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Transposed Matrix:<\/p>\n<p>[[1 3]<\/p>\n<p> [2 4]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u884c\u53cd\u8f6c<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u8f6c\u7f6e\u540e\u7684\u77e9\u9635\u8fdb\u884c\u884c\u53cd\u8f6c\u3002\u5728NumPy\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u64cd\u4f5c\u6765\u5b9e\u73b0\u884c\u53cd\u8f6c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u884c\u53cd\u8f6c\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u884c\u53cd\u8f6c<\/p>\n<p>reversed_matrix = transposed_matrix[::-1]<\/p>\n<p>print(&quot;Reversed Matrix:&quot;)<\/p>\n<p>print(reversed_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u540e\uff0c\u4f60\u5c06\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Reversed Matrix:<\/p>\n<p>[[2 4]<\/p>\n<p> [1 3]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5b8c\u6574\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u7136\u540e\u518d\u8fdb\u884c\u884c\u53cd\u8f6c\u6765\u5b9e\u73b0\u77e9\u9635\u53cd\u8f6c\u7684\u5b8c\u6574\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a2x2\u7684\u77e9\u9635<\/strong><\/h2>\n<p>matrix = np.array([[1, 2], [3, 4]])<\/p>\n<h2><strong>\u8f6c\u7f6e\u77e9\u9635<\/strong><\/h2>\n<p>transposed_matrix = np.transpose(matrix)<\/p>\n<h2><strong>\u884c\u53cd\u8f6c<\/strong><\/h2>\n<p>reversed_matrix = transposed_matrix[::-1]<\/p>\n<h2><strong>\u6253\u5370\u539f\u59cb\u77e9\u9635<\/strong><\/h2>\n<p>print(&quot;Original Matrix:&quot;)<\/p>\n<p>print(matrix)<\/p>\n<h2><strong>\u6253\u5370\u53cd\u8f6c\u540e\u7684\u77e9\u9635<\/strong><\/h2>\n<p>print(&quot;Reversed Matrix:&quot;)<\/p>\n<p>print(reversed_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u540e\uff0c\u4f60\u5c06\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Original Matrix:<\/p>\n<p>[[1 2]<\/p>\n<p> [3 4]]<\/p>\n<p>Reversed Matrix:<\/p>\n<p>[[2 4]<\/p>\n<p> [1 3]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u4f60\u6240\u89c1\uff0c\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u7136\u540e\u518d\u8fdb\u884c\u884c\u53cd\u8f6c\uff0c\u6211\u4eec\u6210\u529f\u5b9e\u73b0\u4e86\u77e9\u9635\u7684\u53cd\u8f6c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u53cd\u8f6c\u77e9\u9635<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528NumPy\u5e93\u548c\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u518d\u8fdb\u884c\u884c\u53cd\u8f6c\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u53cd\u8f6c\u77e9\u9635\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u521b\u5efa2&#215;2\u77e9\u9635\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a2x2\u7684\u77e9\u9635<\/p>\n<p>matrix = [[1, 2], [3, 4]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u53cd\u8f6c\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u53cd\u8f6c\u77e9\u9635\u3002\u4ee5\u4e0b\u662f\u53cd\u8f6c\u77e9\u9635\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u53cd\u8f6c\u77e9\u9635<\/p>\n<p>inverse_matrix = [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]<\/p>\n<p>print(&quot;Inverse Matrix:&quot;)<\/p>\n<p>print(inverse_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u6253\u5370\u7ed3\u679c<\/h4>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u6253\u5370\u51fa\u539f\u59cb\u77e9\u9635\u548c\u53cd\u8f6c\u540e\u7684\u77e9\u9635\uff0c\u4ee5\u4fbf\u67e5\u770b\u7ed3\u679c\u3002\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a2x2\u7684\u77e9\u9635<\/p>\n<p>matrix = [[1, 2], [3, 4]]<\/p>\n<h2><strong>\u53cd\u8f6c\u77e9\u9635<\/strong><\/h2>\n<p>inverse_matrix = [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]<\/p>\n<h2><strong>\u6253\u5370\u539f\u59cb\u77e9\u9635<\/strong><\/h2>\n<p>print(&quot;Original Matrix:&quot;)<\/p>\n<p>print(matrix)<\/p>\n<h2><strong>\u6253\u5370\u53cd\u8f6c\u540e\u7684\u77e9\u9635<\/strong><\/h2>\n<p>print(&quot;Inverse Matrix:&quot;)<\/p>\n<p>print(inverse_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u540e\uff0c\u4f60\u5c06\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Original Matrix:<\/p>\n<p>[[1, 2], [3, 4]]<\/p>\n<p>Inverse Matrix:<\/p>\n<p>[[1, 3], [2, 4]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u4f60\u6240\u89c1\uff0c\u901a\u8fc7\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\uff0c\u6211\u4eec\u6210\u529f\u5b9e\u73b0\u4e86\u77e9\u9635\u7684\u53cd\u8f6c\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u53cd\u8f6c\u77e9\u9635\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u77e9\u9635\u53cd\u8f6c\u5728\u8bb8\u591a\u5b9e\u9645\u5e94\u7528\u4e2d\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u4ecb\u7ecd\u51e0\u4e2a\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7ebf\u6027\u65b9\u7a0b\u7ec4\u6c42\u89e3<\/h4>\n<\/p>\n<p><p>\u5728\u8bb8\u591a\u79d1\u5b66\u548c\u5de5\u7a0b\u8ba1\u7b97\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u6c42\u89e3\u7ebf\u6027\u65b9\u7a0b\u7ec4\u3002\u77e9\u9635\u53cd\u8f6c\u662f\u6c42\u89e3\u7ebf\u6027\u65b9\u7a0b\u7ec4\u7684\u4e00\u4e2a\u91cd\u8981\u6b65\u9aa4\u3002\u901a\u8fc7\u53cd\u8f6c\u7cfb\u6570\u77e9\u9635\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u65b9\u7a0b\u7ec4\u7684\u89e3\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u56fe\u50cf\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u5904\u7406\u9886\u57df\uff0c\u77e9\u9635\u53cd\u8f6c\u4e5f\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f8b\u5982\uff0c\u5728\u56fe\u50cf\u53d8\u6362\u548c\u6ee4\u6ce2\u64cd\u4f5c\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5bf9\u56fe\u50cf\u77e9\u9635\u8fdb\u884c\u53cd\u8f6c\u3002<\/p>\n<\/p>\n<p><h4>3\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a><\/h4>\n<\/p>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u4e2d\uff0c\u77e9\u9635\u53cd\u8f6c\u4e5f\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u5728\u7ebf\u6027\u56de\u5f52\u548c\u6700\u5c0f\u4e8c\u4e58\u6cd5\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u53cd\u8f6c\u77e9\u9635\u6765\u8ba1\u7b97\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u77e9\u9635\u53cd\u8f6c\u65f6\uff0c\u6709\u4e00\u4e9b\u6ce8\u610f\u4e8b\u9879\u9700\u8981\u6211\u4eec\u5173\u6ce8\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u77e9\u9635\u5fc5\u987b\u662f\u65b9\u9635<\/h4>\n<\/p>\n<p><p>\u53ea\u6709\u65b9\u9635\uff08\u5373\u884c\u6570\u548c\u5217\u6570\u76f8\u7b49\u7684\u77e9\u9635\uff09\u624d\u6709\u9006\u77e9\u9635\u3002\u5982\u679c\u77e9\u9635\u4e0d\u662f\u65b9\u9635\uff0c\u5219\u65e0\u6cd5\u8fdb\u884c\u53cd\u8f6c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u77e9\u9635\u5fc5\u987b\u662f\u975e\u5947\u5f02\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u53ea\u6709\u975e\u5947\u5f02\u77e9\u9635\uff08\u5373\u884c\u5217\u5f0f\u4e0d\u4e3a\u96f6\u7684\u77e9\u9635\uff09\u624d\u6709\u9006\u77e9\u9635\u3002\u5982\u679c\u77e9\u9635\u662f\u5947\u5f02\u77e9\u9635\uff0c\u5219\u65e0\u6cd5\u8fdb\u884c\u53cd\u8f6c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u6570\u503c\u7a33\u5b9a\u6027<\/h4>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6570\u503c\u7a33\u5b9a\u6027\u4e5f\u662f\u4e00\u4e2a\u9700\u8981\u5173\u6ce8\u7684\u95ee\u9898\u3002\u5728\u53cd\u8f6c\u77e9\u9635\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u6570\u503c\u4e0d\u7a33\u5b9a\u7684\u60c5\u51b5\uff0c\u5bfc\u81f4\u8ba1\u7b97\u7ed3\u679c\u4e0d\u51c6\u786e\u3002\u56e0\u6b64\uff0c\u5728\u8fdb\u884c\u77e9\u9635\u53cd\u8f6c\u65f6\uff0c\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5\u548c\u6570\u503c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u3001\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u518d\u8fdb\u884c\u884c\u53cd\u8f6c\u3001\u4ee5\u53ca\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c\u3002<strong>\u4f7f\u7528NumPy\u5e93\u662f\u6700\u7b80\u5355\u548c\u5e38\u89c1\u7684\u65b9\u6cd5<\/strong>\uff0c\u901a\u8fc7\u4f7f\u7528<code>numpy.linalg.inv<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u53cd\u8f6c\u77e9\u9635\u3002\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u518d\u8fdb\u884c\u884c\u53cd\u8f6c\u548c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u77e9\u9635\u53cd\u8f6c\uff0c\u4f46\u76f8\u5bf9\u6765\u8bf4\uff0c\u64cd\u4f5c\u6b65\u9aa4\u7a0d\u5fae\u590d\u6742\u4e00\u4e9b\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u77e9\u9635\u53cd\u8f6c\u5728\u8bb8\u591a\u9886\u57df\u90fd\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u4f8b\u5982\u7ebf\u6027\u65b9\u7a0b\u7ec4\u6c42\u89e3\u3001\u56fe\u50cf\u5904\u7406\u548c\u673a\u5668\u5b66\u4e60\u7b49\u3002\u5728\u8fdb\u884c\u77e9\u9635\u53cd\u8f6c\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u77e9\u9635\u5fc5\u987b\u662f\u65b9\u9635\u548c\u975e\u5947\u5f02\u77e9\u9635\uff0c\u5e76\u4e14\u9700\u8981\u5173\u6ce8\u6570\u503c\u7a33\u5b9a\u6027\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c\u64cd\u4f5c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53cd\u8f6c\u77e9\u9635\u901a\u5e38\u662f\u6307\u5bf9\u77e9\u9635\u8fdb\u884c\u8f6c\u7f6e\u6216\u7ffb\u8f6c\u3002\u4f7f\u7528NumPy\u5e93\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u8fd9\u4e00\u64cd\u4f5c\u3002\u53ef\u4ee5\u4f7f\u7528<code>numpy.transpose()<\/code>\u51fd\u6570\u6765\u8f6c\u7f6e\u77e9\u9635\uff0c\u6216\u8005\u4f7f\u7528<code>numpy.flip()<\/code>\u6765\u8fdb\u884c\u7ffb\u8f6c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u77e9\u9635\nmatrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n\n# \u77e9\u9635\u8f6c\u7f6e\ntransposed_matrix = np.transpose(matrix)\n\n# \u77e9\u9635\u7ffb\u8f6c\nflipped_matrix = np.flip(matrix)\n\nprint(transposed_matrix)\nprint(flipped_matrix)\n<\/code><\/pre>\n<p><strong>\u4f7f\u7528Python\u5b9e\u73b0\u77e9\u9635\u53cd\u8f6c\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728\u5b9e\u73b0\u77e9\u9635\u53cd\u8f6c\u65f6\uff0c\u5efa\u8bae\u4f7f\u7528NumPy\u5e93\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u548c\u5185\u7f6e\u51fd\u6570\uff0c\u80fd\u591f\u5904\u7406\u5927\u578b\u77e9\u9635\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u5728\u64cd\u4f5c\u4e4b\u524d\u68c0\u67e5\u77e9\u9635\u7684\u7ef4\u5ea6\uff0c\u4ee5\u514d\u51fa\u73b0\u4e0d\u5fc5\u8981\u7684\u9519\u8bef\u3002\u5bf9\u4e8e\u591a\u7ef4\u77e9\u9635\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u53c2\u6570\u6765\u5b9e\u73b0\u4e0d\u540c\u7ef4\u5ea6\u7684\u7ffb\u8f6c\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u662f\u5426\u53ef\u4ee5\u624b\u52a8\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\u3002\u867d\u7136\u4f7f\u7528NumPy\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u4f46\u5982\u679c\u9700\u8981\u624b\u52a8\u5b9e\u73b0\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u6765\u6784\u5efa\u77e9\u9635\uff0c\u5e76\u4f7f\u7528\u5faa\u73af\u6765\u53cd\u8f6c\u5b83\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u624b\u52a8\u8f6c\u7f6e\u4e00\u4e2a\u77e9\u9635\uff1a<\/p>\n<pre><code class=\"language-python\"># \u624b\u52a8\u8f6c\u7f6e\u77e9\u9635\ndef transpose(matrix):\n    return [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]\n\n# \u793a\u4f8b\u77e9\u9635\nmatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\ntransposed_matrix = transpose(matrix)\n\nprint(transposed_matrix)\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u65b9\u6cd5\u5c55\u793a\u4e86\u5728\u6ca1\u6709NumPy\u5e93\u7684\u60c5\u51b5\u4e0b\u5982\u4f55\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u5b9e\u73b0\u77e9\u9635\u7684\u53cd\u8f6c\u3001\u53ef\u4ee5\u901a\u8fc7\u8f6c\u7f6e\u77e9\u9635\u518d\u8fdb\u884c\u884c\u53cd\u8f6c\u3001\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765 [&hellip;]","protected":false},"author":3,"featured_media":1166756,"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\/1166748"}],"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=1166748"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1166748\/revisions"}],"predecessor-version":[{"id":1166760,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1166748\/revisions\/1166760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1166756"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1166748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1166748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1166748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}