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

distance_matrix(graph, parallel_threshold=300, as_undirected=False, null_value=0.0)[source]#

Get the distance matrix for a graph

This differs from functions like floyd_warshall_numpy() in that the edge weight/data payload is not used and each edge is treated as a distance of 1.

This function is also multithreaded and will run in parallel if the number of nodes in the graph is above the value of parallel_threshold (it defaults to 300). If the function will be running in parallel the env var RAYON_NUM_THREADS can be used to adjust how many threads will be used.

Parameters:
  • graph – The graph to get the distance matrix for, can be either a PyGraph or PyDiGraph.

  • parallel_threshold (int) – The number of nodes to calculate the the distance matrix in parallel at. It defaults to 300, but this can be tuned

  • as_undirected (bool) – If set to True the input directed graph will be treat as if each edge was bidirectional/undirected in the output distance matrix.

  • null_value (float) – An optional float that will treated as a null value. This is the default value in the output matrix and it is used to indicate the absence of an edge between 2 nodes. By default this is 0.0.

Returns:

The distance matrix

Return type:

numpy.ndarray