Created
January 12, 2021 10:02
-
-
Save soyoil/40b3c045f5d03c0a63408fb5bbd69b5d to your computer and use it in GitHub Desktop.
隣接行列から有向グラフを作成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import networkx as nx | |
w = np.array([ | |
[ 0, 0, 0, 8, 15, 0], | |
[10, 0, 24, 0, 8, 0], | |
[ 0, 0, 0, 0, 0, 6], | |
[ 0, 0, 0, 0, 5, 0], | |
[ 0, 0, 12, 0, 0, 7], | |
[ 0, 0, 3, 0, 0, 0] | |
]) | |
G = nx.DiGraph(w) | |
G.graph["graph"] = {"rankdir": "LR"} | |
nx.nx_agraph.view_pygraphviz(G, edgelabel="weight") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment