Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Networkx graph to Sage graph? + Export graph to csv?

Hi everybody,

I want to work with networkx, in particular with algorithms in networkx. I know how to import a graph with data from a csv-file and how to convert a Sage graph into a networkx graph. Therefor my code:

import csv
f=open(DATA+'example','r')
data=csv.reader(f,delimiter=';')
data=[row for row in data]
f.close()
data=[(column[0:]) for column in data[1:]]
data
Liste=[]
for row in data:
     Tupel=()
     for item in row:
          titem=(int(item),)
          Tupel=Tupel+titem
     Liste.append(Tupel)
print Liste
G=Graph(Liste)
import networkx as nx
H=G.networkx_graph()
h=nx.minimum_spanning_tree(H)

What do I have to do to convert my so called h-graph into a Sage graph? And how to get the results back into a csv-file?

Thanks in advance!