python - 在 Python 中将图形转换为标记矩阵
问题描述
我是 Python 绘图的新手,并通过添加边创建了加权有向图。通过不使用有向图,它不是定向的吗?当我尝试将 nx.Graph 更改为 nx.digraph 时,我收到一条错误消息
TypeError: 'module' object is not callable
我还想从图中制作两个矩阵,一个是邻接矩阵,另一个是基于彼此连接的节点(如竞争矩阵)。我能够制作两者,但不再标记节点。我手工完成了连接的节点。
我最终试图对网络进行集群,因此标签很重要。我很感激任何建议。谢谢。
G = nx.Graph()
G.add_edge("N66", "N1", weight=1)
G.add_edge("N19", "N2", weight=1)
G.add_edge("N66", "N4", weight=3)
G.add_edge("N5", "N126", weight=1)
G.add_edge("N5", "N95", weight=1)
G.add_edge("N6", "N126", weight=1)
G.add_edge("N7", "N26", weight=1)
G.add_edge("N61", "N7", weight=1)
G.add_edge("N66", "N7", weight=1)
G.add_edge("N8", "N54", weight=3)
G.add_edge("N8", "N88", weight=1)
G.add_edge("N8", "N97", weight=1)
G.add_edge("N8", "N75", weight=1)
G.add_edge("N19", "N8", weight=1)
G.add_edge("N23", "N8", weight=1)
G.add_edge("N66", "N8", weight=3)
G.add_edge("N40", "N9", weight=1)
G.add_edge("N10", "N69", weight=1)
G.add_edge("N10", "N95", weight=1)...
解决方案
您可能会发现在外部构建一个矩阵更容易,比如 csv 文件并以这种方式读取图形,例如
nx.from_pandas_edgelist(dataframe, source='source', target='target', edge_attr=['weight'])
推荐阅读
- java - 如何使用 .json 文件刷新基本“数据库”
- angular - 带有 intl 的 angular/devextreme 中的自定义日期格式
- c# - .NET 何时尝试解析程序集引用?
- java - 创建一个简单的 Java 规则引擎
- javascript - 如何相对于映射的 div 放置组件?反应 Redux CSS
- ascii - \033[ 中的控制序列列表(用于 urxvt 键符)
- batch-file - 将错误级别与字符进行比较时批处理文件退出
- python - 如何将 5D 张量输入 LSTM?
- java - 如何使用 jsoup 获取 html 类型的 url
- scala.js - 在 Scala.js 外观中,为什么 @js.native 注释排除了 @JSExport 注释?