{"id":1077136,"date":"2025-01-08T11:59:33","date_gmt":"2025-01-08T03:59:33","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1077136.html"},"modified":"2025-01-08T11:59:36","modified_gmt":"2025-01-08T03:59:36","slug":"%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e6%9c%89%e7%89%b9%e5%ae%9a%e5%80%bc%e7%9a%84%e7%9f%a9%e9%98%b5python-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1077136.html","title":{"rendered":"\u5982\u4f55\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181344\/1ad33e01-87ca-4f77-930f-88fb0e27255c.webp\" alt=\"\u5982\u4f55\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635python\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635python<\/strong><\/p>\n<\/p>\n<p><p><strong>\u5728Python\u4e2d\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\uff0c\u53ef\u4ee5\u4f7f\u7528numpy\u5e93\u3001\u5217\u8868\u89e3\u6790\u3001\u91cd\u590d\u7279\u5b9a\u503c\u7684\u65b9\u6cd5\u3002<\/strong> \u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528numpy\u5e93\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u7b80\u4fbf\u4e14\u9ad8\u6548\u7684\u77e9\u9635\u548c\u6570\u7ec4\u64cd\u4f5c\u529f\u80fd\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528numpy\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\uff0c\u5e76\u4ecb\u7ecd\u5176\u4ed6\u4e00\u4e9b\u5e38\u89c1\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u4f7f\u7528numpy\u5e93\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635<\/p>\n<\/p>\n<p><p>numpy\u662fPython\u4e2d\u5904\u7406\u77e9\u9635\u548c\u6570\u7ec4\u7684\u5f3a\u5927\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.full<\/code>\u51fd\u6570\u6765\u751f\u6210\u4e00\u4e2a\u6240\u6709\u5143\u7d20\u90fd\u76f8\u540c\u7684\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a3x3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a5<\/strong><\/h2>\n<p>matrix = np.full((3, 3), 5)<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>numpy.full<\/code>\u51fd\u6570\u751f\u6210\u4e86\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a5\u3002<code>numpy.full<\/code>\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u77e9\u9635\u7684\u5f62\u72b6\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u8981\u586b\u5145\u7684\u503c\u3002<\/p>\n<\/p>\n<p><p>\u9664\u4e86<code>numpy.full<\/code>\uff0cnumpy\u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u4e00\u4e9b\u51fd\u6570\u6765\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.ones<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u6240\u6709\u5143\u7d20\u90fd\u4e3a1\u7684\u77e9\u9635\uff0c\u4f7f\u7528<code>numpy.zeros<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u6240\u6709\u5143\u7d20\u90fd\u4e3a0\u7684\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u4e00\u4e2a3x3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a1<\/p>\n<p>matrix_ones = np.ones((3, 3))<\/p>\n<p>print(matrix_ones)<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a3x3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a0<\/strong><\/h2>\n<p>matrix_zeros = np.zeros((3, 3))<\/p>\n<p>print(matrix_zeros)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<hr>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5217\u8868\u89e3\u6790\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528numpy\u5e93\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u89e3\u6790\u6765\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\u3002\u5217\u8868\u89e3\u6790\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u751f\u6210\u5217\u8868\u7684\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u751f\u6210\u5c0f\u578b\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u4e00\u4e2a3x3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a5<\/p>\n<p>matrix = [[5 for _ in range(3)] for _ in range(3)]<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u5217\u8868\u89e3\u6790\u751f\u6210\u4e86\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a5\u3002\u5217\u8868\u89e3\u6790\u7684\u7b2c\u4e00\u4e2a\u90e8\u5206\u662f\u751f\u6210\u77e9\u9635\u7684\u6bcf\u4e00\u884c\uff0c\u7b2c\u4e8c\u4e2a\u90e8\u5206\u662f\u751f\u6210\u77e9\u9635\u7684\u6240\u6709\u884c\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e09\u3001\u4f7f\u7528\u91cd\u590d\u7279\u5b9a\u503c\u7684\u65b9\u6cd5\u751f\u6210\u77e9\u9635<\/p>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u91cd\u590d\u7279\u5b9a\u503c\u7684\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u751f\u6210\u5927\u578b\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a3x3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a5<\/strong><\/h2>\n<p>matrix = np.tile(5, (3, 3))<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>numpy.tile<\/code>\u51fd\u6570\u751f\u6210\u4e86\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a5\u3002<code>numpy.tile<\/code>\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8981\u91cd\u590d\u7684\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u77e9\u9635\u7684\u5f62\u72b6\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u56db\u3001\u751f\u6210\u5bf9\u89d2\u77e9\u9635<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u751f\u6210\u4e00\u4e2a\u5bf9\u89d2\u77e9\u9635\u3002\u5bf9\u89d2\u77e9\u9635\u662f\u6307\u53ea\u6709\u5bf9\u89d2\u7ebf\u4e0a\u5143\u7d20\u4e0d\u4e3a\u96f6\u7684\u77e9\u9635\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.diag<\/code>\u51fd\u6570\u6765\u751f\u6210\u5bf9\u89d2\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a\u5bf9\u89d2\u77e9\u9635\uff0c\u5bf9\u89d2\u7ebf\u5143\u7d20\u4e3a1, 2, 3<\/strong><\/h2>\n<p>diag_matrix = np.diag([1, 2, 3])<\/p>\n<p>print(diag_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>numpy.diag<\/code>\u51fd\u6570\u751f\u6210\u4e86\u4e00\u4e2a\u5bf9\u89d2\u77e9\u9635\uff0c\u5bf9\u89d2\u7ebf\u5143\u7d20\u4e3a1, 2, 3\u3002<code>numpy.diag<\/code>\u51fd\u6570\u7684\u53c2\u6570\u662f\u5bf9\u89d2\u7ebf\u5143\u7d20\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e94\u3001\u751f\u6210\u5355\u4f4d\u77e9\u9635<\/p>\n<\/p>\n<p><p>\u5355\u4f4d\u77e9\u9635\u662f\u6307\u5bf9\u89d2\u7ebf\u4e0a\u5143\u7d20\u4e3a1\uff0c\u5176\u4f59\u5143\u7d20\u4e3a0\u7684\u77e9\u9635\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.eye<\/code>\u51fd\u6570\u6765\u751f\u6210\u5355\u4f4d\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a3x3\u7684\u5355\u4f4d\u77e9\u9635<\/strong><\/h2>\n<p>identity_matrix = np.eye(3)<\/p>\n<p>print(identity_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>numpy.eye<\/code>\u51fd\u6570\u751f\u6210\u4e86\u4e00\u4e2a3&#215;3\u7684\u5355\u4f4d\u77e9\u9635\u3002<code>numpy.eye<\/code>\u51fd\u6570\u7684\u53c2\u6570\u662f\u77e9\u9635\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u516d\u3001\u751f\u6210\u968f\u673a\u77e9\u9635<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u751f\u6210\u4e00\u4e2a\u968f\u673a\u77e9\u9635\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.random<\/code>\u6a21\u5757\u6765\u751f\u6210\u968f\u673a\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.random.rand<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u5305\u542b\u5747\u5300\u5206\u5e03\u968f\u673a\u6570\u7684\u77e9\u9635\uff0c\u4f7f\u7528<code>numpy.random.randn<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u5305\u542b\u6807\u51c6\u6b63\u6001\u5206\u5e03\u968f\u673a\u6570\u7684\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a3x3\u7684\u77e9\u9635\uff0c\u5305\u542b\u5747\u5300\u5206\u5e03\u968f\u673a\u6570<\/strong><\/h2>\n<p>random_matrix = np.random.rand(3, 3)<\/p>\n<p>print(random_matrix)<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a3x3\u7684\u77e9\u9635\uff0c\u5305\u542b\u6807\u51c6\u6b63\u6001\u5206\u5e03\u968f\u673a\u6570<\/strong><\/h2>\n<p>random_matrix_normal = np.random.randn(3, 3)<\/p>\n<p>print(random_matrix_normal)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>numpy.random.rand<\/code>\u51fd\u6570\u548c<code>numpy.random.randn<\/code>\u51fd\u6570\u751f\u6210\u4e86\u4e24\u4e2a3&#215;3\u7684\u968f\u673a\u77e9\u9635\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e03\u3001\u81ea\u5b9a\u4e49\u51fd\u6570\u751f\u6210\u77e9\u9635<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u751f\u6210\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u77e9\u9635\u3002\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u751f\u6210\u81ea\u5b9a\u4e49\u77e9\u9635\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u751f\u6210\u4e00\u4e2a\u4e0a\u4e09\u89d2\u77e9\u9635\u6216\u4e0b\u4e09\u89d2\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def generate_upper_triangular_matrix(size, value):<\/p>\n<p>    matrix = np.zeros((size, size))<\/p>\n<p>    for i in range(size):<\/p>\n<p>        for j in range(i, size):<\/p>\n<p>            matrix[i][j] = value<\/p>\n<p>    return matrix<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a3x3\u7684\u4e0a\u4e09\u89d2\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a5<\/strong><\/h2>\n<p>upper_triangular_matrix = generate_upper_triangular_matrix(3, 5)<\/p>\n<p>print(upper_triangular_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570<code>generate_upper_triangular_matrix<\/code>\uff0c\u6765\u751f\u6210\u4e00\u4e2a\u4e0a\u4e09\u89d2\u77e9\u9635\u3002\u51fd\u6570\u7684\u53c2\u6570\u662f\u77e9\u9635\u7684\u5927\u5c0f\u548c\u8981\u586b\u5145\u7684\u503c\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u516b\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528numpy\u5e93\u3001\u5217\u8868\u89e3\u6790\u3001\u91cd\u590d\u7279\u5b9a\u503c\u7684\u65b9\u6cd5\u7b49\u3002<strong>\u4f7f\u7528numpy\u5e93\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u7b80\u4fbf\u4e14\u9ad8\u6548\u7684\u77e9\u9635\u548c\u6570\u7ec4\u64cd\u4f5c\u529f\u80fd<\/strong>\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u751f\u6210\u5bf9\u89d2\u77e9\u9635\u3001\u5355\u4f4d\u77e9\u9635\u3001\u968f\u673a\u77e9\u9635\uff0c\u4ee5\u53ca\u901a\u8fc7\u81ea\u5b9a\u4e49\u51fd\u6570\u751f\u6210\u7279\u5b9a\u5f62\u5f0f\u7684\u77e9\u9635\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u751f\u6210\u5404\u79cd\u7c7b\u578b\u7684\u77e9\u9635\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\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\u7279\u5b9a\u503c\u7684\u77e9\u9635\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u8f7b\u677e\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u7279\u5b9a\u503c\u7684\u77e9\u9635\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u5b89\u88c5NumPy\u5e93\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>np.full()<\/code>\u51fd\u6570\u6765\u751f\u6210\u4e00\u4e2a\u586b\u5145\u7279\u5b9a\u503c\u7684\u77e9\u9635\u3002\u4f8b\u5982\uff0c<code>np.full((\u884c\u6570, \u5217\u6570), \u7279\u5b9a\u503c)<\/code>\u5c31\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6307\u5b9a\u5f62\u72b6\u7684\u77e9\u9635\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4e3a\u7279\u5b9a\u503c\u3002<\/p>\n<p><strong>\u53ef\u4ee5\u81ea\u5b9a\u4e49\u77e9\u9635\u7684\u5f62\u72b6\u5417\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\u3002\u5728\u4f7f\u7528NumPy\u521b\u5efa\u77e9\u9635\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u884c\u6570\u548c\u5217\u6570\u6765\u81ea\u5b9a\u4e49\u77e9\u9635\u7684\u5f62\u72b6\u3002\u53ea\u9700\u5728\u521b\u5efa\u77e9\u9635\u65f6\uff0c\u5c06\u6240\u9700\u7684\u884c\u548c\u5217\u4f5c\u4e3a\u5143\u7ec4\u4f20\u9012\u7ed9\u76f8\u5e94\u7684\u51fd\u6570\uff0c\u4f8b\u5982<code>np.zeros((3, 4))<\/code>\u5c06\u751f\u6210\u4e00\u4e2a3\u884c4\u5217\u7684\u96f6\u77e9\u9635\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u751f\u6210\u5305\u542b\u968f\u673a\u503c\u7684\u77e9\u9635\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u4e2d\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u751f\u6210\u5305\u542b\u968f\u673a\u503c\u7684\u77e9\u9635\u3002\u53ef\u4ee5\u4f7f\u7528<code>np.random.rand()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u6307\u5b9a\u5f62\u72b6\u7684\u77e9\u9635\uff0c\u77e9\u9635\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4ecb\u4e8e0\u548c1\u4e4b\u95f4\u7684\u968f\u673a\u503c\u3002\u4f8b\u5982\uff0c<code>np.random.rand(2, 3)<\/code>\u5c06\u751f\u6210\u4e00\u4e2a2\u884c3\u5217\u7684\u77e9\u9635\uff0c\u5176\u4e2d\u6bcf\u4e2a\u503c\u90fd\u662f\u968f\u673a\u751f\u6210\u7684\u3002\u82e5\u9700\u8981\u7279\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>np.random.uniform(\u4e0b\u9650, \u4e0a\u9650, (\u884c\u6570, \u5217\u6570))<\/code>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635python \u5728Python\u4e2d\u751f\u6210\u6709\u7279\u5b9a\u503c\u7684\u77e9\u9635\uff0c\u53ef\u4ee5\u4f7f\u7528numpy\u5e93\u3001\u5217\u8868\u89e3\u6790\u3001\u91cd\u590d\u7279 [&hellip;]","protected":false},"author":3,"featured_media":1077146,"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\/1077136"}],"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=1077136"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1077136\/revisions"}],"predecessor-version":[{"id":1077150,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1077136\/revisions\/1077150"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1077146"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1077136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1077136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1077136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}