Warning

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

networkx.readwrite.sparse6.generate_sparse6

generate_sparse6(G, nodes=None, header=True)[source]

Generate sparse6 format string from an undirected graph.

Parameters:
  • G (Graph (undirected))
  • nodes (list or iterable) – Nodes are labeled 0…n-1 in the order provided. If None the ordering given by G.nodes() is used.
  • header (bool) – If True add ‘>>sparse6<<’ string to head of data
Returns:

s – String in sparse6 format

Return type:

string

Raises:

NetworkXError – If the graph is directed

Examples

>>> G = nx.MultiGraph([(0, 1), (0, 1), (0, 1)])
>>> nx.generate_sparse6(G)
'>>sparse6<<:A_'

Notes

The format does not support edge or node labels.

References

[1]Sparse6 specification <http://users.cecs.anu.edu.au/~bdm/data/formats.html>