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

PyDiGraph.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.

>>> G = rx.PyDiGraph()
>>> G.extend_from_edge_list([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> node = 2
>>> G.neighbors_undirected(node)
NodeIndices[3, 1]
>>> G.to_undirected().neighbors(node)
NodeIndices[1, 3]

For direction-aware neighbors, see predecessors() and successors().

Parameters:

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

Returns:

A list of the neighboring node indices

Return type:

NodeIndices