depth_first_tree(csgraph, i_start, directed=True)
Note that a tree generated by a depth-first search is not unique: it depends on the order that the children of each node are searched.
The N x N matrix representing the compressed sparse graph. The input csgraph will be converted to csr format for the calculation.
The index of starting node.
If True (default), then operate on a directed graph: only move from point i to point j along paths csgraph[i, j]. If False, then find the shortest path on an undirected graph: the algorithm can progress from point i to j along csgraph[i, j] or csgraph[j, i].
The N x N directed compressed-sparse representation of the depth- first tree drawn from csgraph, starting at the specified node.
Return a tree generated by a depth-first search.
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import depth_first_tree
X = csr_matrix([[0, 8, 0, 3],
[0, 0, 2, 5],
[0, 0, 0, 6],
[0, 0, 0, 0]])
Tcsr = depth_first_tree(X, 0, directed=False)
Tcsr.toarray().astype(int)
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