少女祈祷中...

用NetworkX来创建、计算图

默认创建的是undirected graph,当然也可以使用direct graph的class:

1
2
3
4
5
6
7
8
9
10
11
12
import networkx as nx
# Create an undirected graph G
G = nx.Graph()
print(G.is_directed()) #false

# Create a directed graph H
H = nx.DiGraph()
print(H.is_directed())

# Add graph level attribute
G.graph["Name"] = "Bar"
print(G.graph)