NoSQL Solution for Persisting Graphs at Scale

后端 未结 3 1071
抹茶落季
抹茶落季 2021-01-29 22:03

I\'m hooked on using Python and NetworkX for analyzing graphs and as I learn more I want to use more and more data (guess I\'m becoming a data junkie :-). Eventually I think my

3条回答
  •  走了就别回头了
    2021-01-29 22:29

    I would be interested to see the best way of using the hard drive. In the past I have made multiple graphs and saved them as .dot files. Then kind of mixed some of them in memory somehow. Not the best solution though.

    from random import random
    import networkx as nx
    
    def make_graph():
        G=nx.DiGraph()
        N=10
        #make a random graph
        for i in range(N):
            for j in range(i):
                if 4*random()<1:
                    G.add_edge(i,j)
    
        nx.write_dot(G,"savedgraph.dot")
        return G
    
    try:
        G=nx.read_dot("savedgraph.dot")
    except:
        G=make_graph() #This will fail if you don't use the same seed but have created the graph in the past. You could use the Singleton design pattern here.
    print G.adj
    

提交回复
热议问题