graph - 如何在 Python 中可视化 torch_geometric 图?
问题描述
让我们考虑一个例子,我有以下坐标格式的邻接矩阵:
> edge_index.numpy() = array([[ 0, 1, 0, 3, 2],
[ 1, 0, 3, 2, 1]], dtype=int64)
这意味着节点0链接到节点1,反之亦然,节点0链接到3等等......
你知道用 nx.draw() 在 networkx 中绘制这个图的方法吗?
谢谢你。
解决方案
import networkx as nx
edge_index = torch.tensor([[0, 1, 1, 2],
[1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = torch_geometric.data.Data(x=x, edge_index=edge_index)
g = torch_geometric.utils.to_networkx(data, to_undirected=True)
nx.draw(g)
推荐阅读
- node.js - 使用 Base64 的 AWS Kinesis 数据
- c# - Entity Framework Core:在包含子集合时进行查询时的性能
- typescript - Visual Studio 代码调试器找不到带有科尔多瓦和打字稿的源图
- php - 使用 PHP 7 在 QNAP 上安装 Vtiger 7
- database - 在 codeigniter 图像正在上传到数据库但没有插入到图像文件夹中
- r - 闪亮的应用程序 - 使用 1 个按钮将 2 个操作文件下载到当前目录
- java - Checkmarx SAST 扫描代码,在 pom.xml 中有外部无法访问的依赖项
- node.js - 邮递员只显示错误消息并且没有请求正在工作
- dji-sdk - DJI Mavic Air 2 相机无法设置模式?
- spring - @CacheEvict 是否立即执行缓存驱逐?