{"id":1084373,"date":"2025-01-08T13:06:41","date_gmt":"2025-01-08T05:06:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1084373.html"},"modified":"2025-01-08T13:06:43","modified_gmt":"2025-01-08T05:06:43","slug":"python-%e9%82%bb%e6%8e%a5%e7%9f%a9%e9%98%b5%e5%a6%82%e4%bd%95%e8%ae%a1%e7%ae%97%e5%8f%af%e8%be%be%e7%9f%a9%e9%98%b5-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1084373.html","title":{"rendered":"Python \u90bb\u63a5\u77e9\u9635\u5982\u4f55\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24194747\/254a1268-1084-48b9-9eb3-11b2664db6e2.webp\" alt=\"Python \u90bb\u63a5\u77e9\u9635\u5982\u4f55\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u4f7f\u7528\u90bb\u63a5\u77e9\u9635\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u6700\u4e3b\u8981\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Floyd-Warshall\u7b97\u6cd5\u3001\u4f7f\u7528\u77e9\u9635\u5e42\u4ee5\u53ca\u4f7f\u7528\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\uff08DFS\uff09\u6216\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\uff08BFS\uff09\u7b49\u3002<\/strong>\u5176\u4e2d\uff0c<strong>Floyd-Warshall\u7b97\u6cd5<\/strong>\u662f\u4e00\u79cd\u7ecf\u5178\u7684\u52a8\u6001\u89c4\u5212\u7b97\u6cd5\uff0c\u7528\u4e8e\u89e3\u51b3\u56fe\u7684\u5168\u5bf9\u5168\u6700\u77ed\u8def\u5f84\u95ee\u9898\uff0c\u5e76\u53ef\u4ee5\u6709\u6548\u5730\u7528\u4e8e\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u3002\u5177\u4f53\u5b9e\u73b0\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7Python\u7684NumPy\u5e93\u6765\u7b80\u5316\u77e9\u9635\u8fd0\u7b97\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001Floyd-Warshall\u7b97\u6cd5<\/h3>\n<\/p>\n<p><p>Floyd-Warshall\u7b97\u6cd5\u662f\u4e00\u79cd\u7528\u4e8e\u8ba1\u7b97\u6240\u6709\u8282\u70b9\u5bf9\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u7684\u7b97\u6cd5\uff0c\u8fd9\u4f7f\u5f97\u5b83\u4e5f\u9002\u7528\u4e8e\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u3002\u7b97\u6cd5\u7684\u4e3b\u8981\u601d\u60f3\u662f\u901a\u8fc7\u52a8\u6001\u89c4\u5212\u9010\u6b65\u66f4\u65b0\u8def\u5f84\u4fe1\u606f\uff0c\u6700\u7ec8\u5f97\u5230\u53ef\u8fbe\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7b97\u6cd5\u4ecb\u7ecd<\/h4>\n<\/p>\n<p><p>Floyd-Warshall\u7b97\u6cd5\u901a\u8fc7\u4e09\u91cd\u5faa\u73af\u9010\u6b65\u66f4\u65b0\u8def\u5f84\u4fe1\u606f\uff0c\u6838\u5fc3\u601d\u60f3\u662f\u68c0\u67e5\u6bcf\u4e00\u5bf9\u8282\u70b9 (i, j) \u662f\u5426\u901a\u8fc7\u4e2d\u95f4\u8282\u70b9 k \u53ef\u8fbe\u3002\u8bbe\u521d\u59cb\u90bb\u63a5\u77e9\u9635\u4e3a <code>adj_matrix<\/code>\uff0c\u8282\u70b9 i \u5230 j \u7684\u8def\u5f84\u957f\u5ea6\u4e3a <code>adj_matrix[i][j]<\/code>\u3002\u5982\u679c\u5b58\u5728\u4e00\u4e2a\u4e2d\u95f4\u8282\u70b9 k \u4f7f\u5f97\u4ece i \u5230 j \u7684\u8def\u5f84\u6bd4\u76f4\u63a5\u4ece i \u5230 j \u66f4\u77ed\uff0c\u5219\u66f4\u65b0\u8def\u5f84\u957f\u5ea6\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5b9e\u73b0\u6b65\u9aa4<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u548cNumPy\u5e93\u5b9e\u73b0Floyd-Warshall\u7b97\u6cd5\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u7684\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def floyd_warshall(adj_matrix):<\/p>\n<p>    n = len(adj_matrix)<\/p>\n<p>    reach_matrix = np.copy(adj_matrix)<\/p>\n<p>    for k in range(n):<\/p>\n<p>        for i in range(n):<\/p>\n<p>            for j in range(n):<\/p>\n<p>                reach_matrix[i][j] = reach_matrix[i][j] or (reach_matrix[i][k] and reach_matrix[k][j])<\/p>\n<p>    return reach_matrix<\/p>\n<h2><strong>\u793a\u4f8b\u90bb\u63a5\u77e9\u9635\uff080\u8868\u793a\u65e0\u8fde\u63a5\uff0c1\u8868\u793a\u6709\u8fde\u63a5\uff09<\/strong><\/h2>\n<p>adj_matrix = np.array([<\/p>\n<p>    [0, 1, 0, 0],<\/p>\n<p>    [0, 0, 1, 0],<\/p>\n<p>    [0, 0, 0, 1],<\/p>\n<p>    [1, 0, 0, 0]<\/p>\n<p>])<\/p>\n<p>reach_matrix = floyd_warshall(adj_matrix)<\/p>\n<p>print(&quot;\u53ef\u8fbe\u77e9\u9635:&quot;)<\/p>\n<p>print(reach_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u590d\u5236\u4e86\u90bb\u63a5\u77e9\u9635 <code>adj_matrix<\/code>\uff0c\u5e76\u901a\u8fc7\u9010\u6b65\u66f4\u65b0\u8def\u5f84\u4fe1\u606f\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635 <code>reach_matrix<\/code>\u3002\u6700\u7ec8\u8f93\u51fa\u7684 <code>reach_matrix<\/code> \u5373\u4e3a\u6240\u6709\u8282\u70b9\u5bf9\u4e4b\u95f4\u7684\u53ef\u8fbe\u6027\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u77e9\u9635\u5e42<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u77e9\u9635\u5e42\u7684\u65b9\u6cd5\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u57fa\u4e8e\u4e00\u79cd\u7b80\u5355\u7684\u6570\u5b66\u601d\u60f3\uff1a\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u53ef\u4ee5\u901a\u8fc7 k \u6b65\u4ece\u4e00\u4e2a\u8282\u70b9\u5230\u8fbe\u53e6\u4e00\u4e2a\u8282\u70b9\uff0c\u90a3\u4e48\u5bf9\u5e94\u7684\u90bb\u63a5\u77e9\u9635\u7684 k \u6b21\u5e42\u4e2d\u7684\u5143\u7d20\u5c06\u662f\u975e\u96f6\u7684\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7b97\u6cd5\u4ecb\u7ecd<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0d\u65ad\u5730\u5c06\u90bb\u63a5\u77e9\u9635\u8fdb\u884c\u5e42\u8fd0\u7b97\uff0c\u76f4\u5230\u8fbe\u5230\u56fe\u4e2d\u6700\u957f\u7684\u8def\u5f84\u957f\u5ea6\uff08\u5373\u8282\u70b9\u6570\u51cf\u4e00\uff09\uff0c\u7136\u540e\u68c0\u67e5\u6bcf\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u975e\u96f6\u3002\u5982\u679c\u67d0\u4e2a\u5143\u7d20\u4e3a\u975e\u96f6\uff0c\u5219\u8868\u793a\u5bf9\u5e94\u7684\u8282\u70b9\u5bf9\u662f\u53ef\u8fbe\u7684\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5b9e\u73b0\u6b65\u9aa4<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u548cNumPy\u5e93\u5b9e\u73b0\u77e9\u9635\u5e42\u65b9\u6cd5\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u7684\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def matrix_power_reachability(adj_matrix):<\/p>\n<p>    n = len(adj_matrix)<\/p>\n<p>    reach_matrix = np.copy(adj_matrix)<\/p>\n<p>    power_matrix = np.copy(adj_matrix)<\/p>\n<p>    for _ in range(1, n):<\/p>\n<p>        power_matrix = np.dot(power_matrix, adj_matrix)<\/p>\n<p>        reach_matrix = np.logical_or(reach_matrix, power_matrix)<\/p>\n<p>    return reach_matrix.astype(int)<\/p>\n<h2><strong>\u793a\u4f8b\u90bb\u63a5\u77e9\u9635\uff080\u8868\u793a\u65e0\u8fde\u63a5\uff0c1\u8868\u793a\u6709\u8fde\u63a5\uff09<\/strong><\/h2>\n<p>adj_matrix = np.array([<\/p>\n<p>    [0, 1, 0, 0],<\/p>\n<p>    [0, 0, 1, 0],<\/p>\n<p>    [0, 0, 0, 1],<\/p>\n<p>    [1, 0, 0, 0]<\/p>\n<p>])<\/p>\n<p>reach_matrix = matrix_power_reachability(adj_matrix)<\/p>\n<p>print(&quot;\u53ef\u8fbe\u77e9\u9635:&quot;)<\/p>\n<p>print(reach_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u9010\u6b65\u8ba1\u7b97\u90bb\u63a5\u77e9\u9635\u7684\u5e42\uff0c\u5e76\u5bf9\u6bcf\u4e00\u6b65\u7684\u7ed3\u679c\u8fdb\u884c\u903b\u8f91\u6216\u8fd0\u7b97\uff0c\u6700\u7ec8\u5f97\u5230\u53ef\u8fbe\u77e9\u9635 <code>reach_matrix<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\uff08DFS\uff09\u548c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\uff08BFS\uff09<\/h3>\n<\/p>\n<p><p>\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\uff08DFS\uff09\u548c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\uff08BFS\uff09\u662f\u4e24\u79cd\u7ecf\u5178\u7684\u56fe\u904d\u5386\u7b97\u6cd5\uff0c\u53ef\u4ee5\u7528\u6765\u8ba1\u7b97\u4ece\u6bcf\u4e2a\u8282\u70b9\u51fa\u53d1\u7684\u53ef\u8fbe\u6027\u4fe1\u606f\uff0c\u4ece\u800c\u6784\u5efa\u53ef\u8fbe\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>1\u3001DFS\u7b97\u6cd5\u4ecb\u7ecd<\/h4>\n<\/p>\n<p><p>DFS\u662f\u4e00\u79cd\u5229\u7528\u6808\u7ed3\u6784\u7684\u56fe\u904d\u5386\u7b97\u6cd5\uff0c\u901a\u8fc7\u9012\u5f52\u6216\u663e\u5f0f\u6808\u5b9e\u73b0\u3002\u5b83\u4ece\u4e00\u4e2a\u8d77\u59cb\u8282\u70b9\u5f00\u59cb\uff0c\u6cbf\u7740\u672a\u8bbf\u95ee\u8fc7\u7684\u8282\u70b9\u4e0d\u65ad\u6df1\u5165\uff0c\u76f4\u5230\u65e0\u6cd5\u7ee7\u7eed\u4e3a\u6b62\uff0c\u7136\u540e\u56de\u6eaf\u5230\u4e0a\u4e00\u4e2a\u8282\u70b9\u7ee7\u7eed\u641c\u7d22\u3002<\/p>\n<\/p>\n<p><h4>2\u3001BFS\u7b97\u6cd5\u4ecb\u7ecd<\/h4>\n<\/p>\n<p><p>BFS\u662f\u4e00\u79cd\u5229\u7528\u961f\u5217\u7ed3\u6784\u7684\u56fe\u904d\u5386\u7b97\u6cd5\uff0c\u4ece\u4e00\u4e2a\u8d77\u59cb\u8282\u70b9\u5f00\u59cb\uff0c\u9996\u5148\u8bbf\u95ee\u6240\u6709\u76f8\u90bb\u8282\u70b9\uff0c\u7136\u540e\u518d\u8bbf\u95ee\u8fd9\u4e9b\u76f8\u90bb\u8282\u70b9\u7684\u76f8\u90bb\u8282\u70b9\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002BFS\u9002\u5408\u7528\u4e8e\u5bfb\u627e\u6700\u77ed\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h4>3\u3001DFS\u5b9e\u73b0\u6b65\u9aa4<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u5b9e\u73b0DFS\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u7684\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def dfs(graph, start, visited):<\/p>\n<p>    stack = [start]<\/p>\n<p>    while stack:<\/p>\n<p>        node = stack.pop()<\/p>\n<p>        for neighbor, connected in enumerate(graph[node]):<\/p>\n<p>            if connected and not visited[neighbor]:<\/p>\n<p>                visited[neighbor] = 1<\/p>\n<p>                stack.append(neighbor)<\/p>\n<p>def dfs_reachability(adj_matrix):<\/p>\n<p>    n = len(adj_matrix)<\/p>\n<p>    reach_matrix = np.zeros((n, n), dtype=int)<\/p>\n<p>    for i in range(n):<\/p>\n<p>        visited = np.zeros(n, dtype=int)<\/p>\n<p>        dfs(adj_matrix, i, visited)<\/p>\n<p>        reach_matrix[i] = visited<\/p>\n<p>    return reach_matrix<\/p>\n<h2><strong>\u793a\u4f8b\u90bb\u63a5\u77e9\u9635\uff080\u8868\u793a\u65e0\u8fde\u63a5\uff0c1\u8868\u793a\u6709\u8fde\u63a5\uff09<\/strong><\/h2>\n<p>adj_matrix = np.array([<\/p>\n<p>    [0, 1, 0, 0],<\/p>\n<p>    [0, 0, 1, 0],<\/p>\n<p>    [0, 0, 0, 1],<\/p>\n<p>    [1, 0, 0, 0]<\/p>\n<p>])<\/p>\n<p>reach_matrix = dfs_reachability(adj_matrix)<\/p>\n<p>print(&quot;\u53ef\u8fbe\u77e9\u9635:&quot;)<\/p>\n<p>print(reach_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7DFS\u904d\u5386\u6bcf\u4e2a\u8282\u70b9\u7684\u53ef\u8fbe\u6027\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u53ef\u8fbe\u77e9\u9635 <code>reach_matrix<\/code> \u4e2d\u3002<\/p>\n<\/p>\n<p><h4>4\u3001BFS\u5b9e\u73b0\u6b65\u9aa4<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u5b9e\u73b0BFS\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u7684\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from collections import deque<\/p>\n<p>def bfs(graph, start, visited):<\/p>\n<p>    queue = deque([start])<\/p>\n<p>    visited[start] = 1<\/p>\n<p>    while queue:<\/p>\n<p>        node = queue.popleft()<\/p>\n<p>        for neighbor, connected in enumerate(graph[node]):<\/p>\n<p>            if connected and not visited[neighbor]:<\/p>\n<p>                visited[neighbor] = 1<\/p>\n<p>                queue.append(neighbor)<\/p>\n<p>def bfs_reachability(adj_matrix):<\/p>\n<p>    n = len(adj_matrix)<\/p>\n<p>    reach_matrix = np.zeros((n, n), dtype=int)<\/p>\n<p>    for i in range(n):<\/p>\n<p>        visited = np.zeros(n, dtype=int)<\/p>\n<p>        bfs(adj_matrix, i, visited)<\/p>\n<p>        reach_matrix[i] = visited<\/p>\n<p>    return reach_matrix<\/p>\n<h2><strong>\u793a\u4f8b\u90bb\u63a5\u77e9\u9635\uff080\u8868\u793a\u65e0\u8fde\u63a5\uff0c1\u8868\u793a\u6709\u8fde\u63a5\uff09<\/strong><\/h2>\n<p>adj_matrix = np.array([<\/p>\n<p>    [0, 1, 0, 0],<\/p>\n<p>    [0, 0, 1, 0],<\/p>\n<p>    [0, 0, 0, 1],<\/p>\n<p>    [1, 0, 0, 0]<\/p>\n<p>])<\/p>\n<p>reach_matrix = bfs_reachability(adj_matrix)<\/p>\n<p>print(&quot;\u53ef\u8fbe\u77e9\u9635:&quot;)<\/p>\n<p>print(reach_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7BFS\u904d\u5386\u6bcf\u4e2a\u8282\u70b9\u7684\u53ef\u8fbe\u6027\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u53ef\u8fbe\u77e9\u9635 <code>reach_matrix<\/code> \u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Python\u4e2d\u4f7f\u7528\u90bb\u63a5\u77e9\u9635\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u3002<strong>Floyd-Warshall\u7b97\u6cd5<\/strong>\u901a\u8fc7\u52a8\u6001\u89c4\u5212\u9010\u6b65\u66f4\u65b0\u8def\u5f84\u4fe1\u606f\uff0c\u9002\u7528\u4e8e\u89e3\u51b3\u5168\u5bf9\u5168\u6700\u77ed\u8def\u5f84\u95ee\u9898\uff1b<strong>\u77e9\u9635\u5e42<\/strong>\u65b9\u6cd5\u901a\u8fc7\u9010\u6b65\u8ba1\u7b97\u90bb\u63a5\u77e9\u9635\u7684\u5e42\uff0c\u5e76\u5bf9\u6bcf\u4e00\u6b65\u7684\u7ed3\u679c\u8fdb\u884c\u903b\u8f91\u6216\u8fd0\u7b97\uff0c\u6700\u7ec8\u5f97\u5230\u53ef\u8fbe\u77e9\u9635\uff1b<strong>DFS<\/strong>\u548c<strong>BFS<\/strong>\u901a\u8fc7\u56fe\u904d\u5386\u7b97\u6cd5\uff0c\u5206\u522b\u5229\u7528\u6808\u548c\u961f\u5217\u7ed3\u6784\uff0c\u4ece\u6bcf\u4e2a\u8282\u70b9\u51fa\u53d1\u8ba1\u7b97\u5176\u53ef\u8fbe\u6027\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u5177\u4f53\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u5e94\u7528\u573a\u666f\u548c\u56fe\u7684\u6027\u8d28\u6765\u51b3\u5b9a\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4ece\u90bb\u63a5\u77e9\u9635\u4e2d\u63d0\u53d6\u53ef\u8fbe\u77e9\u9635\uff1f<\/strong><br \/>\u53ef\u8fbe\u77e9\u9635\u662f\u4e00\u4e2a\u8868\u793a\u56fe\u4e2d\u8282\u70b9\u95f4\u53ef\u8fbe\u5173\u7cfb\u7684\u77e9\u9635\u3002\u53ef\u4ee5\u901a\u8fc7\u5bf9\u90bb\u63a5\u77e9\u9635\u8fdb\u884c\u5e42\u8fd0\u7b97\u6216\u4f7f\u7528\u56fe\u904d\u5386\u7b97\u6cd5\uff08\u5982\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u6216\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\uff09\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u3002\u5177\u4f53\u65b9\u6cd5\u662f\u4f7f\u7528\u90bb\u63a5\u77e9\u9635\u7684\u5e42\u8fd0\u7b97\uff0c\u76f4\u5230\u8fbe\u5230\u6240\u9700\u7684\u8def\u5f84\u957f\u5ea6\uff0c\u6216\u8005\u901a\u8fc7\u904d\u5386\u6240\u6709\u8282\u70b9\u6765\u6807\u8bb0\u53ef\u8fbe\u8282\u70b9\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u65f6\uff0c\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u4f7f\u7528\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u8fdb\u884c\u77e9\u9635\u8fd0\u7b97\uff0c\u5b83\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u6570\u7ec4\u64cd\u4f5c\u529f\u80fd\uff0c\u9002\u5408\u5904\u7406\u90bb\u63a5\u77e9\u9635\u3002\u6b64\u5916\uff0cNetworkX\u5e93\u4e5f\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u4e13\u4e3a\u56fe\u8bba\u548c\u7f51\u7edc\u5206\u6790\u8bbe\u8ba1\uff0c\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u56fe\u5e76\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u3002<\/p>\n<p><strong>\u53ef\u8fbe\u77e9\u9635\u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u53ef\u8fbe\u77e9\u9635\u5728\u8bb8\u591a\u9886\u57df\u90fd\u6709\u5e94\u7528\uff0c\u5982\u793e\u4ea4\u7f51\u7edc\u5206\u6790\u3001\u4ea4\u901a\u7f51\u7edc\u4f18\u5316\u548c\u8ba1\u7b97\u673a\u7f51\u7edc\u8bbe\u8ba1\u7b49\u3002\u5728\u793e\u4ea4\u7f51\u7edc\u4e2d\uff0c\u53ef\u8fbe\u77e9\u9635\u53ef\u4ee5\u5e2e\u52a9\u8bc6\u522b\u793e\u4ea4\u5708\u5b50\u548c\u5f71\u54cd\u529b\u4f20\u64ad\uff0c\u800c\u5728\u4ea4\u901a\u7f51\u7edc\u4e2d\uff0c\u53ef\u4ee5\u5206\u6790\u4e0d\u540c\u5730\u70b9\u95f4\u7684\u53ef\u8fbe\u6027\uff0c\u4ee5\u4f18\u5316\u8def\u7ebf\u89c4\u5212\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u4f7f\u7528\u90bb\u63a5\u77e9\u9635\u6765\u8ba1\u7b97\u53ef\u8fbe\u77e9\u9635\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u6700\u4e3b\u8981\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Floyd-Warsh [&hellip;]","protected":false},"author":3,"featured_media":1084378,"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\/1084373"}],"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=1084373"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084373\/revisions"}],"predecessor-version":[{"id":1084379,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084373\/revisions\/1084379"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1084378"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1084373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1084373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1084373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}