star_graph#

star_graph(n, create_using=None)[source]#

Return a star graph.

The star graph consists of one center node connected to n outer nodes.

(Source code, png)

../../_images/networkx-generators-classic-star_graph-1.png
Parameters:
nint or iterable

If an integer, node labels are 0 to n, with center 0. If an iterable of nodes, the center is the first. Warning: n is not checked for duplicates and if present, the resulting graph may not be as desired. Make sure you have no duplicates.

create_usingNetworkX graph constructor, optional (default=nx.Graph)

Graph type to create. If graph instance, then cleared before populated.

Notes

The graph has n + 1 nodes for integer n. So star_graph(3) is the same as star_graph(range(4)).

Examples

A star graph with 3 spokes can be generated with

>>> G = nx.star_graph(3)
>>> sorted(G.edges)
[(0, 1), (0, 2), (0, 3)]

For directed graphs, the convention is to have edges pointing from the hub to the spokes:

>>> DG1 = nx.star_graph(3, create_using=nx.DiGraph)
>>> sorted(DG1.edges)
[(0, 1), (0, 2), (0, 3)]

Other possible definitions have edges pointing from the spokes to the hub:

>>> DG2 = nx.star_graph(3, create_using=nx.DiGraph).reverse()
>>> sorted(DG2.edges)
[(1, 0), (2, 0), (3, 0)]

or have bidirectional edges:

>>> DG3 = nx.star_graph(3).to_directed()
>>> sorted(DG3.edges)
[(0, 1), (0, 2), (0, 3), (1, 0), (2, 0), (3, 0)]
----

Additional backends implement this function

cugraph : GPU-accelerated backend.