创建图
# 创建一个空图(不包含节点和边)
G = nx.Graph()
# 添加节点
G.add_nodes_from([1,2,3,4])
# 添加边
G.add_edges_from([(1,2),(1,3),(2,3),(2,4)])
# 可视化
nx.draw(G, node_size=500, with_labels=True)
创建有向图
G = nx.DiGraph()
# 添加节点
G.add_nodes_from([1,2,3,4])
# 添加边
G.add_edges_from([(1,2),(1,3),(2,3),(3,4)])
nx.draw(G, node_size=500, with_labels=True)
创建加权图
G = nx.Graph()
G.add_weighted_edges_from([(0, 1, 3.0), (1, 2, 7.5), (0, 2, 1.5)])
As = nx.adjacency_matrix(G)
print(As.todense())
nx.draw(G, node_size=800, with_labels=True)
💗💗💗
print("如果文章对你有用,请点个赞呗O(∩_∩)O~")
System.out.println("如果文章对你有用,请点个赞呗O(∩_∩)O~");
cout<<"如果文章对你有用,请点个赞呗O(∩_∩)O~"<<endl;
💗💗💗