Computing the distance matrix from an adjacency matrix in python

≯℡__Kan透↙ 提交于 2021-01-29 07:58:30

问题


Write a code that produces the distance matrix from a graph (graph theory), the code should use the adjacency matrix and cannot use any functions from NetworkX module, apart from networkx.adjacency_matrix().

I understand the process of how the distance matrix works. My theory of how the adjacency matrix is involved is that it takes an element that connects two nodes and adds the distance up. For example, lets say i have nodes A, B and C. A is connected to B, and B is connected to C. The distance between two connected nodes is 1. So the distance from A to C would be 2.

My only problem is how i can implement this into a code so that it creates a distance matrix for any given graph.

Thank you for any help, sorry if my explanation is unclear, please let me know if you would like me to clarify anything.

来源:https://stackoverflow.com/questions/55328620/computing-the-distance-matrix-from-an-adjacency-matrix-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!