#### Previous topic

scipy.sparse.csgraph.NegativeCycleError

#### Next topic

scipy.sparse.csgraph.csgraph_from_dense

# scipy.sparse.csgraph.construct_dist_matrix¶

scipy.sparse.csgraph.construct_dist_matrix(graph, predecessors, directed=True, null_value=np.inf)

Construct distance matrix from a predecessor matrix

New in version 0.11.0.

Parameters: graph : array_like or sparse The N x N matrix representation of a directed or undirected graph. If dense, then non-edges are indicated by zeros or infinities. predecessors : array_like The N x N matrix of predecessors of each node (see Notes below). directed : bool, optional 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 operate on an undirected graph: the algorithm can progress from point i to j along csgraph[i, j] or csgraph[j, i]. null_value : bool, optional value to use for distances between unconnected nodes. Default is np.inf dist_matrix : ndarray The N x N matrix of distances between nodes along the path specified by the predecessor matrix. If no path exists, the distance is zero.

Notes

The predecessor matrix is of the form returned by graph_shortest_path. Row i of the predecessor matrix contains information on the shortest paths from point i: each entry predecessors[i, j] gives the index of the previous node in the path from point i to point j. If no path exists between point i and j, then predecessors[i, j] = -9999