from_nested_tuple(sequence, sensible_relabeling=False)
The nested tuple representation of a tree is defined recursively. The tree with one node and no edges is represented by the empty tuple, ()
. A tree with k
subtrees is represented by a tuple of length k
in which each element is the nested tuple representation of a subtree.
This function is not the inverse of to_nested_tuple
; the only guarantee is that the rooted trees are isomorphic.
A nested tuple representing a rooted tree.
Whether to relabel the nodes of the tree so that nodes are labeled in increasing order according to their breadth-first search order from the root node.
The tree corresponding to the given nested tuple, whose root node is node 0. If sensible_labeling
is True
, nodes will be labeled in breadth-first search order starting from the root node.
Returns the rooted tree corresponding to the given nested tuple.
See :>>> balanced = (((), ()), ((), ())) >>> T = nx.from_nested_tuple(balanced, sensible_relabeling=True) >>> edges = [(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)] >>> all((u, v) in T.edges() or (v, u) in T.edges() for (u, v) in edges) True
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.tree.coding.from_prufer_sequence
networkx.algorithms.tree.coding.to_nested_tuple
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them