【问题标题】:How to add new edges to the stellargraph dataset?如何向 stellargraph 数据集添加新边?
【发布时间】:2021-09-21 15:13:18
【问题描述】:

我需要使用 stellargraph 向 Cora 数据集添加一些额外的边。有没有办法向 stellargraph 库中的当前数据集添加边?

import stellargraph as sg
dataset = sg.datasets.Cora()

例如在 NetworkX 中,我们可以使用 add_edges_from(edgelist) 向现有图添加一些边。

【问题讨论】:

    标签: python pandas dataframe networkx stellargraph


    【解决方案1】:

    自 0.9 版以来,您无法直接从 stellargraph 执行此操作。 您必须使用 .to_networkx() 将其转换回 networkX 格式,添加边缘,然后将其转换回 stellargraph。

    from stellargraph import StellarGraph
    import networkx as nx
    
    g = StellarGraph.to_networkx(dataset)
    g.add_edges_from(edgelist)
    new_dataset = StellarGraph.from_networkx(g)
    

    【讨论】:

      猜你喜欢
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多