This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
- empty_graph(n=0, create_using=None)¶
Return the empty graph with n nodes and zero edges.
Node labels are the integers 0 to n-1
For example: >>> G=nx.empty_graph(10) >>> G.number_of_nodes() 10 >>> G.number_of_edges() 0
The variable create_using should point to a “graph”-like object that will be cleaned (nodes and edges will be removed) and refitted as an empty “graph” with n nodes with integer labels. This capability is useful for specifying the class-nature of the resulting empty “graph” (i.e. Graph, DiGraph, MyWeirdGraphClass, etc.).
The variable create_using has two main uses: Firstly, the variable create_using can be used to create an empty digraph, network,etc. For example,
>>> n=10 >>> G=nx.empty_graph(n,create_using=nx.DiGraph())
will create an empty digraph on n nodes.
Secondly, one can pass an existing graph (digraph, pseudograph, etc.) via create_using. For example, if G is an existing graph (resp. digraph, pseudograph, etc.), then empty_graph(n,create_using=G) will empty G (i.e. delete all nodes and edges using G.clear() in base) and then add n nodes and zero edges, and return the modified graph (resp. digraph, pseudograph, etc.).
See also create_empty_copy(G).