【问题标题】:How to keep/assign node names when contracting vertices in igraph?在 igraph 中收缩顶点时如何保留/分配节点名称?
【发布时间】:2015-03-06 02:27:19
【问题描述】:

我正在尝试在 igraph 中收缩一些顶点(使用 python api),同时保留顶点的名称。我不清楚如何保留图形的名称属性。图表的节点是人,我正在尝试折叠名称损坏的人。

我查看了 R 文档,但仍然不知道该怎么做。

例如,如果我执行以下任一操作,我会收到错误消息。

smallgraph.contract_vertices([0,1,2,3,4,2,6],vertex.attr.comb=[name='first'])

smallgraph.contract_vertices([0,1,2,3,4,2,6],vertex.attr.comb=['first'])

【问题讨论】:

    标签: python igraph


    【解决方案1】:

    在 Python 中,您需要的关键字参数称为 combine_attrs 而不是 vertex.attr.comb。导入 igraph 后,从 Python 命令行查看help(Graph.contract_vertices)。此外,关键字参数接受单个说明符(例如first)或字典。您的第一个示例无效,因为它根本不是有效的 Python 语法。第二个示例不起作用,因为您传递了一个带有单个项目而不是单个项目的 list。

    因此,正确的变体应该是:

    smallgraph.contract_vertices([0,1,2,3,4,2,6], combine_attrs=dict(name="first"))
    smallgraph.contract_vertices([0,1,2,3,4,2,6], combine_attrs="first")
    

    【讨论】:

      【解决方案2】:

      没关系。您可以不使用措辞直接输入字典

      vertex.attr.comb   
      

      【讨论】:

        猜你喜欢
        • 2012-10-24
        • 2012-05-06
        • 2021-12-01
        • 2021-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多