{"id":1086958,"date":"2025-01-08T13:30:41","date_gmt":"2025-01-08T05:30:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1086958.html"},"modified":"2025-01-08T13:30:44","modified_gmt":"2025-01-08T05:30:44","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python%e6%9e%84%e9%80%a0%e4%b8%80%e4%b8%aa%e7%9f%a9%e9%98%b5-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1086958.html","title":{"rendered":"\u5982\u4f55\u5728python\u6784\u9020\u4e00\u4e2a\u77e9\u9635"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24200119\/25064473-9b87-4b0d-a610-abbb1f4e9f90.webp\" alt=\"\u5982\u4f55\u5728python\u6784\u9020\u4e00\u4e2a\u77e9\u9635\" \/><\/p>\n<p><p> <strong>\u5728 Python \u4e2d\u6784\u9020\u77e9\u9635\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u4f8b\u5982\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u3001NumPy \u5e93\u6216 Pandas \u5e93\u3002<\/strong> \u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u5177\u4f53\u9009\u62e9\u53d6\u51b3\u4e8e\u4f60\u7684\u9700\u6c42\u548c\u9879\u76ee\u7684\u5177\u4f53\u60c5\u51b5\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u6784\u9020\u77e9\u9635<\/h3>\n<\/p>\n<p><p>\u5d4c\u5957\u5217\u8868\u662f\u6700\u57fa\u7840\u7684\u6784\u9020\u77e9\u9635\u7684\u65b9\u6cd5\u3002\u5728 Python \u4e2d\uff0c\u5217\u8868\u662f\u4e00\u4e2a\u7075\u6d3b\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u6765\u8868\u793a\u77e9\u9635\u7684\u884c\u548c\u5217\u3002\u6bcf\u4e2a\u5217\u8868\u7684\u5143\u7d20\u672c\u8eab\u53c8\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u8868\u793a\u77e9\u9635\u7684\u4e00\u884c\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6784\u9020\u4e00\u4e2a3x3\u7684\u77e9\u9635<\/p>\n<p>matrix = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<h2><strong>\u6253\u5370\u77e9\u9635<\/strong><\/h2>\n<p>for row in matrix:<\/p>\n<p>    print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f18\u70b9\u548c\u7f3a\u70b9<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1a\u5d4c\u5957\u5217\u8868\u65b9\u6cd5\u7b80\u5355\u76f4\u89c2\uff0c\u4e0d\u9700\u8981\u989d\u5916\u5b89\u88c5\u5e93\uff0c\u9002\u5408\u5c0f\u89c4\u6a21\u77e9\u9635\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1a\u5f53\u77e9\u9635\u89c4\u6a21\u8f83\u5927\u65f6\uff0c\u5d4c\u5957\u5217\u8868\u7684\u64cd\u4f5c\u4f1a\u53d8\u5f97\u590d\u6742\u4e14\u4f4e\u6548\u3002\u7f3a\u4e4f\u79d1\u5b66\u8ba1\u7b97\u548c\u77e9\u9635\u64cd\u4f5c\u7684\u9ad8\u7ea7\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528 NumPy \u5e93\u6784\u9020\u77e9\u9635<\/h3>\n<\/p>\n<p><p>NumPy \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u77e9\u9635\u548c\u6570\u7ec4\u64cd\u4f5c\u529f\u80fd\u3002\u4f7f\u7528 NumPy \u6784\u9020\u77e9\u9635\u4e0d\u4ec5\u7b80\u6d01\u9ad8\u6548\uff0c\u8fd8\u80fd\u65b9\u4fbf\u5730\u8fdb\u884c\u77e9\u9635\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5 NumPy<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528 NumPy \u4e4b\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5\u8be5\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\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><h4>\u793a\u4f8b\u4ee3\u7801<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u6784\u9020\u4e00\u4e2a3x3\u7684\u77e9\u9635<\/strong><\/h2>\n<p>matrix = np.array([<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>])<\/p>\n<h2><strong>\u6253\u5370\u77e9\u9635<\/strong><\/h2>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f18\u70b9\u548c\u7f3a\u70b9<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1aNumPy \u63d0\u4f9b\u4e86\u591a\u79cd\u77e9\u9635\u64cd\u4f5c\u51fd\u6570\uff0c\u5982\u77e9\u9635\u4e58\u6cd5\u3001\u8f6c\u7f6e\u3001\u6c42\u9006\u7b49\uff0c\u9002\u5408\u5927\u89c4\u6a21\u77e9\u9635\u548c\u590d\u6742\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1a\u9700\u8981\u989d\u5916\u5b89\u88c5 NumPy \u5e93\uff0c\u5bf9\u521d\u5b66\u8005\u53ef\u80fd\u4e0d\u592a\u53cb\u597d\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528 Pandas \u5e93\u6784\u9020\u77e9\u9635<\/h3>\n<\/p>\n<p><p>Pandas \u662f\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u4e3b\u8981\u7528\u4e8e\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u867d\u7136 Pandas \u4e3b\u8981\u7528\u4e8e\u5904\u7406\u8868\u683c\u6570\u636e\uff0c\u4f46\u4e5f\u53ef\u4ee5\u7528\u6765\u6784\u9020\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5 Pandas<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528 Pandas \u4e4b\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5\u8be5\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u6784\u9020\u4e00\u4e2a3x3\u7684\u77e9\u9635<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;A&#39;: [1, 2, 3],<\/p>\n<p>    &#39;B&#39;: [4, 5, 6],<\/p>\n<p>    &#39;C&#39;: [7, 8, 9]<\/p>\n<p>}<\/p>\n<p>matrix = pd.DataFrame(data)<\/p>\n<h2><strong>\u6253\u5370\u77e9\u9635<\/strong><\/h2>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f18\u70b9\u548c\u7f3a\u70b9<\/h4>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1aPandas \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u529f\u80fd\uff0c\u9002\u5408\u4e0e\u8868\u683c\u6570\u636e\u7ed3\u5408\u4f7f\u7528\u3002\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u7b5b\u9009\u3001\u7edf\u8ba1\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1aPandas \u7684\u77e9\u9635\u64cd\u4f5c\u529f\u80fd\u4e0d\u5982 NumPy \u4e13\u4e1a\uff0c\u4e3b\u8981\u7528\u4e8e\u6570\u636e\u5206\u6790\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u77e9\u9635\u7684\u57fa\u672c\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\u6784\u9020\u77e9\u9635\uff0c\u90fd\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u64cd\u4f5c\uff0c\u5982\u77e9\u9635\u7684\u52a0\u6cd5\u3001\u4e58\u6cd5\u3001\u8f6c\u7f6e\u7b49\u3002\u4e0b\u9762\u5c06\u5206\u522b\u4ecb\u7ecd\u8fd9\u4e9b\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>\u77e9\u9635\u52a0\u6cd5<\/h4>\n<\/p>\n<p><p>\u77e9\u9635\u52a0\u6cd5\u662f\u6307\u5bf9\u5e94\u4f4d\u7f6e\u7684\u5143\u7d20\u76f8\u52a0\u3002\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u548c NumPy \u90fd\u53ef\u4ee5\u5b9e\u73b0\u77e9\u9635\u52a0\u6cd5\u3002<\/p>\n<\/p>\n<p><h5>\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u5b9e\u73b0\u77e9\u9635\u52a0\u6cd5<\/h5>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5d4c\u5957\u5217\u8868\u5b9e\u73b0\u77e9\u9635\u52a0\u6cd5<\/p>\n<p>def matrix_addition(matrix1, matrix2):<\/p>\n<p>    result = []<\/p>\n<p>    for i in range(len(matrix1)):<\/p>\n<p>        row = []<\/p>\n<p>        for j in range(len(matrix1[0])):<\/p>\n<p>            row.append(matrix1[i][j] + matrix2[i][j])<\/p>\n<p>        result.append(row)<\/p>\n<p>    return result<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>matrix1 = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<p>matrix2 = [<\/p>\n<p>    [9, 8, 7],<\/p>\n<p>    [6, 5, 4],<\/p>\n<p>    [3, 2, 1]<\/p>\n<p>]<\/p>\n<p>result = matrix_addition(matrix1, matrix2)<\/p>\n<p>for row in result:<\/p>\n<p>    print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h5>\u4f7f\u7528 NumPy \u5b9e\u73b0\u77e9\u9635\u52a0\u6cd5<\/h5>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>matrix1 = np.array([<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>])<\/p>\n<p>matrix2 = np.array([<\/p>\n<p>    [9, 8, 7],<\/p>\n<p>    [6, 5, 4],<\/p>\n<p>    [3, 2, 1]<\/p>\n<p>])<\/p>\n<p>result = matrix1 + matrix2<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u77e9\u9635\u4e58\u6cd5<\/h4>\n<\/p>\n<p><p>\u77e9\u9635\u4e58\u6cd5\u662f\u6307\u77e9\u9635\u4e0e\u77e9\u9635\u4e4b\u95f4\u7684\u4e58\u6cd5\uff0c\u9700\u6ee1\u8db3\u77e9\u9635\u4e58\u6cd5\u7684\u6761\u4ef6\uff0c\u5373\u7b2c\u4e00\u4e2a\u77e9\u9635\u7684\u5217\u6570\u7b49\u4e8e\u7b2c\u4e8c\u4e2a\u77e9\u9635\u7684\u884c\u6570\u3002<\/p>\n<\/p>\n<p><h5>\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u5b9e\u73b0\u77e9\u9635\u4e58\u6cd5<\/h5>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5d4c\u5957\u5217\u8868\u5b9e\u73b0\u77e9\u9635\u4e58\u6cd5<\/p>\n<p>def matrix_multiplication(matrix1, matrix2):<\/p>\n<p>    result = [[0 for _ in range(len(matrix2[0]))] for _ in range(len(matrix1))]<\/p>\n<p>    for i in range(len(matrix1)):<\/p>\n<p>        for j in range(len(matrix2[0])):<\/p>\n<p>            for k in range(len(matrix2)):<\/p>\n<p>                result[i][j] += matrix1[i][k] * matrix2[k][j]<\/p>\n<p>    return result<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>matrix1 = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<p>matrix2 = [<\/p>\n<p>    [9, 8],<\/p>\n<p>    [6, 5],<\/p>\n<p>    [3, 2]<\/p>\n<p>]<\/p>\n<p>result = matrix_multiplication(matrix1, matrix2)<\/p>\n<p>for row in result:<\/p>\n<p>    print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h5>\u4f7f\u7528 NumPy \u5b9e\u73b0\u77e9\u9635\u4e58\u6cd5<\/h5>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>matrix1 = np.array([<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>])<\/p>\n<p>matrix2 = np.array([<\/p>\n<p>    [9, 8],<\/p>\n<p>    [6, 5],<\/p>\n<p>    [3, 2]<\/p>\n<p>])<\/p>\n<p>result = np.dot(matrix1, matrix2)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u77e9\u9635\u8f6c\u7f6e<\/h4>\n<\/p>\n<p><p>\u77e9\u9635\u8f6c\u7f6e\u662f\u6307\u5c06\u77e9\u9635\u7684\u884c\u548c\u5217\u4e92\u6362\u3002<\/p>\n<\/p>\n<p><h5>\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u5b9e\u73b0\u77e9\u9635\u8f6c\u7f6e<\/h5>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5d4c\u5957\u5217\u8868\u5b9e\u73b0\u77e9\u9635\u8f6c\u7f6e<\/p>\n<p>def transpose(matrix):<\/p>\n<p>    result = [[0 for _ in range(len(matrix))] for _ in range(len(matrix[0]))]<\/p>\n<p>    for i in range(len(matrix)):<\/p>\n<p>        for j in range(len(matrix[0])):<\/p>\n<p>            result[j][i] = matrix[i][j]<\/p>\n<p>    return result<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>matrix = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<p>result = transpose(matrix)<\/p>\n<p>for row in result:<\/p>\n<p>    print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h5>\u4f7f\u7528 NumPy \u5b9e\u73b0\u77e9\u9635\u8f6c\u7f6e<\/h5>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>matrix = np.array([<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>])<\/p>\n<p>result = np.transpose(matrix)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728 Python \u4e2d\u6784\u9020\u77e9\u9635\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u5305\u62ec\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u3001NumPy \u5e93\u548c Pandas \u5e93\u7b49\u3002<strong>\u5d4c\u5957\u5217\u8868\u65b9\u6cd5\u7b80\u5355\u76f4\u89c2\uff0c\u4f46\u5728\u5904\u7406\u5927\u89c4\u6a21\u77e9\u9635\u65f6\u6548\u7387\u8f83\u4f4e\uff1bNumPy \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u77e9\u9635\u64cd\u4f5c\u51fd\u6570\uff0c\u9002\u5408\u79d1\u5b66\u8ba1\u7b97\u548c\u5927\u89c4\u6a21\u77e9\u9635\u7684\u64cd\u4f5c\uff1bPandas \u5219\u4e3b\u8981\u7528\u4e8e\u6570\u636e\u5206\u6790\u573a\u666f\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\u3002<\/strong> \u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u5e0c\u671b\u4f60\u80fd\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1\u5728 Python \u4e2d\u6784\u9020\u77e9\u9635\u7684\u65b9\u6cd5\uff0c\u5e76\u80fd\u591f\u719f\u7ec3\u5730\u8fdb\u884c\u77e9\u9635\u7684\u57fa\u672c\u64cd\u4f5c\u3002\u65e0\u8bba\u662f\u6570\u636e\u5206\u6790\u3001\u79d1\u5b66\u8ba1\u7b97\u8fd8\u662f<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\uff0c\u77e9\u9635\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\uff0c\u638c\u63e1\u5176\u64cd\u4f5c\u5bf9\u4e8e\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u548c\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u90fd\u5177\u6709\u91cd\u8981\u610f\u4e49\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u6784\u9020\u77e9\u9635\u65f6\uff0cPython\u4e2d\u6709\u54ea\u4e9b\u5e38\u7528\u7684\u5e93\u548c\u5de5\u5177\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6784\u9020\u77e9\u9635\u6700\u5e38\u7528\u7684\u5e93\u662fNumPy\u3002NumPy\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u7ec4\u5bf9\u8c61\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u548c\u64cd\u4f5c\u591a\u7ef4\u6570\u7ec4\u3002\u4f7f\u7528<code>numpy.array()<\/code>\u53ef\u4ee5\u5c06\u5217\u8868\u6216\u5143\u7ec4\u8f6c\u5316\u4e3a\u77e9\u9635\uff0c\u4f7f\u7528<code>numpy.zeros()<\/code>\u548c<code>numpy.ones()<\/code>\u53ef\u4ee5\u521b\u5efa\u5168\u96f6\u6216\u5168\u4e00\u7684\u77e9\u9635\u3002\u6b64\u5916\uff0c<code>numpy.arange()<\/code>\u548c<code>numpy.reshape()<\/code>\u4e5f\u53ef\u4ee5\u5e2e\u52a9\u751f\u6210\u7279\u5b9a\u5f62\u72b6\u7684\u77e9\u9635\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u521d\u59cb\u5316\u4e00\u4e2a\u968f\u673a\u77e9\u9635\uff1f<\/strong><br \/>\u82e5\u60f3\u5728Python\u4e2d\u521d\u59cb\u5316\u4e00\u4e2a\u968f\u673a\u77e9\u9635\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u7684<code>numpy.random.rand()<\/code>\u6216<code>numpy.random.randn()<\/code>\u51fd\u6570\u3002<code>rand()<\/code>\u751f\u62100\u52301\u4e4b\u95f4\u5747\u5300\u5206\u5e03\u7684\u968f\u673a\u6570\uff0c\u800c<code>randn()<\/code>\u751f\u6210\u6807\u51c6\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u6570\u3002\u53ea\u9700\u4f20\u5165\u6240\u9700\u7684\u884c\u6570\u548c\u5217\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5373\u53ef\u8f7b\u677e\u521b\u5efa\u968f\u673a\u77e9\u9635\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5bf9\u6784\u9020\u7684\u77e9\u9635\u8fdb\u884c\u57fa\u672c\u64cd\u4f5c\uff1f<\/strong><br \/>\u5bf9\u6784\u9020\u7684\u77e9\u9635\u8fdb\u884c\u57fa\u672c\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5229\u7528NumPy\u63d0\u4f9b\u7684\u591a\u79cd\u529f\u80fd\u3002\u53ef\u4ee5\u8fdb\u884c\u77e9\u9635\u52a0\u6cd5\u3001\u4e58\u6cd5\u548c\u8f6c\u7f6e\u7b49\u64cd\u4f5c\u3002\u4f7f\u7528<code>numpy.dot()<\/code>\u53ef\u4ee5\u5b9e\u73b0\u77e9\u9635\u4e58\u6cd5\uff0c\u4f7f\u7528<code>numpy.transpose()<\/code>\u6216<code>.T<\/code>\u5c5e\u6027\u53ef\u4ee5\u83b7\u53d6\u77e9\u9635\u7684\u8f6c\u7f6e\u3002\u6b64\u5916\uff0cNumPy\u8fd8\u652f\u6301\u5143\u7d20\u7ea7\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u53ef\u4ee5\u76f4\u63a5\u5bf9\u77e9\u9635\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\uff0c\u8fd9\u4f7f\u5f97\u77e9\u9635\u8fd0\u7b97\u53d8\u5f97\u975e\u5e38\u9ad8\u6548\u548c\u7b80\u5355\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728 Python \u4e2d\u6784\u9020\u77e9\u9635\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u4f8b\u5982\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u3001NumPy \u5e93\u6216 Pandas \u5e93\u3002 \u8fd9\u4e9b\u65b9\u6cd5 [&hellip;]","protected":false},"author":3,"featured_media":1086963,"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\/1086958"}],"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=1086958"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1086958\/revisions"}],"predecessor-version":[{"id":1086964,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1086958\/revisions\/1086964"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1086963"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1086958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1086958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1086958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}