Skip to content

Instantly share code, notes, and snippets.

@Jaya472
Jaya472 / gist:db0945e9c2016fbd2c206d7ab7254c69
Created December 5, 2023 00:54
Create a weighted network using networkx library
import networkx as nx
#for a 14 node network with connections as below. Each tuple represents a connected edge
edge_list = [(1, 2),(1,3),(1,8),(2,3),(2,4),(3,6),(4,5),(4,11),(5,6),(5,7),(6,10),(6,14),(7,8),(8,9),(9,10),(9,12),(9,13),(11,12),(11,13),(12,14),(14,13)]
G = nx.Graph() #to create the graph structure with unidirectional edges
#Use the below DiGraph() for bi-directional edges
# G = nx.DiGraph()