将python-igraph图转换为networkx [英] Convert python-igraph graph to networkx

查看:356
本文介绍了将python-igraph图转换为networkx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我一直在使用python-igraph软件包,并且我所有的代码都基于我使用igraph创建的图形.现在,我需要为我的图计算一些度量,这些度量显然是在networkx中实现的,而不是在igraph中实现的,例如(katz_centrality_numpy,edge_betweenness_centrality,...).我想知道是否有一种方法可以在这两个程序包之间将一个图形转换为另一个图形,并避免再次读取文件,因为我的文件很大并且必须重复很多相同的过程.

Recently I've been working with python-igraph package and all my code is based on graphs I create using igraph. Right now, I need to calculate some measures for my graph which apparently are implemented in networkx and not in igraph such as (katz_centrality_numpy, edge_betweenness_centrality, ...). I am wondering if there is a way to convert one graph to another between these two packages and to avoid reading from files again since my files are huge and have to repeat the same process alot.

顺便说一句,当我将igraph图传递给networkx函数时,我收到以下错误:

By the way, when I pass the igraph graph to a networkx function I receive the following error:

TypeError: 'Graph' object is not iterable

谢谢:)

推荐答案

您可以启动带有边的networkx图:

You can initiate a networkx graph with edges:

Graph([(1,2), (3,4)])

请参见文档.

这是使用方法(感谢nimafl的代码):

This is how to use it (Thank you nimafl for the code):

graphigraph图,我们创建了G这是networkx图.

graph is the igraph graph and we create G which is a networkx graph.

import networkx
A = graph.get_edgelist()
G = networkx.DiGraph(A) # In case your graph is directed
G = networkx.Graph(A) # In case you graph is undirected

这篇关于将python-igraph图转换为networkx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆