Python_NetWorkX_教程

NetworkX

import networkx as nx


一、创建空的图

1.G = nx.Graph() #创建无向图
2.G = nx.Digraph() #创建有向图

二、添加节点Nodeedgeweighted_edge

  • Graph.__init__(**attr[, data]) Initialize a graph with edges, name, graph attributes.

  • Graph.add_node(n, **attr[, attr_dict]) Add a single node n and update node attributes.

  • Graph.add_nodes_from(nodes, **attr) Add multiple nodes.

  • Graph.remove_node(n) Remove node n.

  • Graph.remove_nodes_from(nodes) Remove multiple nodes.

  • Graph.add_edge(u, v, **attr[, attr_dict]) Add an edge between u and v.

  • Graph.add_edges_from(ebunch,**attr[,attr_dict])Add all the edges in ebunch.

  • Graph.add_weighted_edges_from(ebunch,**attr)Add all the edges in ebunch as weighted edges with specified weights.

  • Graph.remove_edge(u, v) Remove the edge between u and v.

  • Graph.remove_edges_from(ebunch) Remove all edges specified in ebunch.

  • Graph.add_star(nodes, **attr) Add a star.

  • Graph.add_path(nodes, **attr) Add a path.

  • Graph.add_cycle(nodes, **attr) Add a cycle.

  • Graph.clear() Remove all nodes and edges from the graph.

三、迭代节点Nodeedge

迭代nodes和edges

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值