0

I am new to graphing in Python and have created a weighted directed graph by adding edges. By not using digraph is it not directed? And when I try to change nx.Graph to nx.digraph I get an error saying

TypeError: 'module' object is not callable

I would also like to make two matrices from the graph, one an adjacency and the other based off nodes that are connected to each other (like a competition matrix). I was able to make both but the nodes were no longer labeled. I did the connected nodes one by hand.

I am eventually trying to cluster the network so labels are important. I appreciate any advice. Thanks.

G = nx.Graph()
    
G.add_edge("N66", "N1", weight=1)
G.add_edge("N19", "N2", weight=1)
G.add_edge("N66", "N4", weight=3)
G.add_edge("N5", "N126", weight=1)
G.add_edge("N5", "N95", weight=1)
G.add_edge("N6", "N126", weight=1)
G.add_edge("N7", "N26", weight=1)
G.add_edge("N61", "N7", weight=1)
G.add_edge("N66", "N7", weight=1)
G.add_edge("N8", "N54", weight=3)
G.add_edge("N8", "N88", weight=1)
G.add_edge("N8", "N97", weight=1)
G.add_edge("N8", "N75", weight=1)
G.add_edge("N19", "N8", weight=1)
G.add_edge("N23", "N8", weight=1)
G.add_edge("N66", "N8", weight=3)
G.add_edge("N40", "N9", weight=1)
G.add_edge("N10", "N69", weight=1)
G.add_edge("N10", "N95", weight=1)...
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
Kay
  • 13
  • 2
  • *"when I try to change nx.Graph to nx.digraph I get an error"* can you show the code you tried that produced this error? – Cory Kramer Aug 02 '21 at 14:46

1 Answers1

0

You may find it easier to construct a matrix externally say as a csv file and read the graph in that way with something like

nx.from_pandas_edgelist(dataframe, source='source', target='target', edge_attr=['weight'])
Landon
  • 93
  • 11