Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

complete_multipartite_graph

complete_multipartite_graph(*block_sizes)[source]

Returns the complete multipartite graph with the specified block sizes.

Parameters:block_sizes (tuple of integers) – The number of vertices in each block of the multipartite graph. The length of this tuple is the number of blocks.
Returns:G – Returns the complete multipartite graph with the specified block sizes.

For each node, the node attribute 'block' is an integer indicating which block contains the node.

Return type:NetworkX Graph

Examples

Creating a complete tripartite graph, with blocks of one, two, and three vertices, respectively.

>>> import networkx as nx
>>> G = nx.complete_multipartite_graph(1, 2, 3)
>>> [G.node[u]['block'] for u in G]
[0, 1, 1, 2, 2, 2]
>>> G.edges(0)
[(0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]
>>> G.edges(2)
[(2, 0), (2, 3), (2, 4), (2, 5)]
>>> G.edges(4)
[(4, 0), (4, 1), (4, 2)]

Notes

This function generalizes several other graph generator functions.

  • If no block sizes are given, this returns the null graph.
  • If a single block size n is given, this returns the empty graph on n nodes.
  • If two block sizes m and n are given, this returns the complete bipartite graph on m + n nodes.
  • If block sizes 1 and n are given, this returns the star graph on n + 1 nodes.

See also

complete_bipartite_graph()