MCPcopy
hub / github.com/networkx/networkx / empty_graph

Function empty_graph

networkx/generators/classic.py:566–660  ·  view source on GitHub ↗

Returns the empty graph with n nodes and zero edges. .. plot:: >>> nx.draw(nx.empty_graph(5)) Parameters ---------- n : int or iterable container of nodes (default = 0) If n is an integer, nodes are from `range(n)`. If n is a container of nodes, those nodes

(n=0, create_using=None, default=Graph)

Source from the content-addressed store, hash-verified

564@nx._dispatchable(graphs=None, returns_graph=True)
565@nodes_or_number(0)
566def empty_graph(n=0, create_using=None, default=Graph):
567 """Returns the empty graph with n nodes and zero edges.
568
569 .. plot::
570
571 >>> nx.draw(nx.empty_graph(5))
572
573 Parameters
574 ----------
575 n : int or iterable container of nodes (default = 0)
576 If n is an integer, nodes are from `range(n)`.
577 If n is a container of nodes, those nodes appear in the graph.
578 create_using : Graph Instance, Constructor or None
579 Indicator of type of graph to return.
580 If a Graph-type instance, then clear and use it.
581 If None, use the `default` constructor.
582 If a constructor, call it to create an empty graph.
583 default : Graph constructor (optional, default = nx.Graph)
584 The constructor to use if create_using is None.
585 If None, then nx.Graph is used.
586 This is used when passing an unknown `create_using` value
587 through your home-grown function to `empty_graph` and
588 you want a default constructor other than nx.Graph.
589
590 Examples
591 --------
592 >>> G = nx.empty_graph(10)
593 >>> G.number_of_nodes()
594 10
595 >>> G.number_of_edges()
596 0
597 >>> G = nx.empty_graph("ABC")
598 >>> G.number_of_nodes()
599 3
600 >>> sorted(G)
601 ['A', 'B', 'C']
602
603 Notes
604 -----
605 The variable create_using should be a Graph Constructor or a
606 "graph"-like object. Constructors, e.g. `nx.Graph` or `nx.MultiGraph`
607 will be used to create the returned graph. "graph"-like objects
608 will be cleared (nodes and edges will be removed) and refitted as
609 an empty "graph" with nodes specified in n. This capability
610 is useful for specifying the class-nature of the resulting empty
611 "graph" (i.e. Graph, DiGraph, MyWeirdGraphClass, etc.).
612
613 The variable create_using has three main uses:
614 Firstly, the variable create_using can be used to create an
615 empty digraph, multigraph, etc. For example,
616
617 >>> n = 10
618 >>> G = nx.empty_graph(n, create_using=nx.DiGraph)
619
620 will create an empty digraph on n nodes.
621
622 Secondly, one can pass an existing graph (digraph, multigraph,
623 etc.) via create_using. For example, if G is an existing graph

Callers 15

LCF_graphFunction · 0.90
sedgewick_maze_graphFunction · 0.90
grid_2d_graphFunction · 0.90
grid_graphFunction · 0.90
triangular_lattice_graphFunction · 0.90
hexagonal_lattice_graphFunction · 0.90
gn_graphFunction · 0.90
gnr_graphFunction · 0.90
gnc_graphFunction · 0.90
full_rary_treeFunction · 0.70

Calls 2

clearMethod · 0.45
add_nodes_fromMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…