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.PyDAG.neighbors_undirected#

PyDAG.neighbors_undirected(node, /)#

Get the direction-agnostic neighbors (i.e. successors and predecessors) of a node.

This is functionally equivalent to converting the directed graph to an undirected graph, and calling neighbors thereon. For example:

import rustworkx

dag = rustworkx.generators.directed_cycle_graph(num_nodes=10, bidirectional=False)

node = 3
neighbors = dag.neighbors_undirected(node)
same_neighbors = dag.to_undirected().neighbors(node)

assert sorted(neighbors) == sorted(same_neighbors)
Parameters:

node (int) – The index of the node to get the neighbors of

Returns:

A list of the neighbor node indices

Return type:

NodeIndices