How can I generate a dynamic graph from a list of graphs on Networkx or DyNetx

Youssef Snoussi :

Well what I have is a bunch of edges files that I managed to put in a list of graphs, but the problem is I want to process them as a single dynamic network but I don't have any clue on how to do it, I've been looking all around the documentation of networkx and dynetx with no response; So here's what I've done so far:

import networkx as nx
import matplotlib.pyplot as plt
from operator import itemgetter
import dynetx as dnx
#from glob import glob
import os

#path to the files
path = '../Ants'
#Create a list of graph from the files
G = [nx.read_weighted_edgelist(path+'/'+f, create_using=nx.Graph(), nodetype=int) for f in os.listdir(path) ]

Sparky05 :

The DyNetx package states some methods in their DynGraph documentation. The following should solve your problem:

import networkx as nx
import matplotlib.pyplot as plt
from operator import itemgetter
import dynetx as dnx
#from glob import glob
import os

#path to the files
path = '../Ants'
#Create a list of graph from the files
list_of_snapshots = [nx.read_weighted_edgelist(path+'/'+f, create_using=nx.Graph(), nodetype=int) for f in os.listdir(path) ]

dynamic_graph = dnx.DynGraph()
for t, graph in enumerate(list_of_snapshots):
    dynamic_graph.add_interactions_from(graph.edges(data=True), t=t)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=361621&siteId=1