Skip to content

Instantly share code, notes, and snippets.

@soyoil
Created January 12, 2021 10:02
Show Gist options
  • Save soyoil/40b3c045f5d03c0a63408fb5bbd69b5d to your computer and use it in GitHub Desktop.
Save soyoil/40b3c045f5d03c0a63408fb5bbd69b5d to your computer and use it in GitHub Desktop.
隣接行列から有向グラフを作成する
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