Note
This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.
rustworkx.PyDiGraph.predecessor_indices#
- PyDiGraph.predecessor_indices(node, /)#
Return a list of predecessor node indices in a directed graph
A predecessor is defined as a node that has a directed edge pointing to the specified node. In a multigraph, where two nodes can be connected by multiple edges, each predecessor node index is returned only once.
>>> G = rx.PyDiGraph() >>> G.add_nodes_from(["A", "B", "C", "D", "E"]) NodeIndices[0, 1, 2, 3, 4] >>> G.extend_from_edge_list([(0, 3), (1, 3), (2, 3), (3, 4)]) >>> G.predecessor_indices(3) # predecessors of the 'D' node NodeIndices[2, 1, 0]
To get the data of these nodes, see [predecessors]
To filter the predecessors by the attributes of the connecting edge, see
find_predecessors_by_edge()
.See also
successor_indices()
.For undirected graphs, see
neighbors()
.- Parameters:
node (int) – The index of the node to get the predecessors for
- Returns:
A list of the node indices of all node’s predecessors
- Return type: