igraph
公式ウェブサイト:https://igraph.org/python/#startpy
は、インストールが含ま所见即所得
れていないことに注意する価値がありますがpip install igraph
、次のとおりです。
pip install python-igraph
タイトルなどの内容、この記事で紹介するのはnetworkx
、igraph
その間の変換です。
1.networkx
回すigraph
import networkx as nx
import igraph as ig
g = nx.karate_club_graph()
d = nx.to_pandas_edgelist(g).values
g = ig.Graph(d)
for v in g.vs:
print(v)
2.igraph
回すnetworkx
import networkx as nx
import igraph as ig
g = nx.karate_club_graph()
d = nx.to_pandas_edgelist(g).values
g = ig.Graph(d)
t = [str(e[0])+" "+str(e[1]) for e in g.get_edgelist()]
f = nx.parse_adjlist(t)
print(f.nodes)
['0', '1', '2', '3', '4', '5', '6', '7', '8', '10', '11', '12', '13', '17', '19', '21', '31', '30', '9', '27', '28', '32', '16', '33', '14', '15', '18', '20', '22', '23', '25', '29', '24', '26']