graph

graph2data(graph)

Returns the index and data of a sparse matrix.

Parameters:

graph (csr_matrix) – A sparse matrix of the edges in a graph and corresponding node indexes.

Returns:

Returns a tuple of the following:

  • index1, index2 (array) – Arrays of the node indices of the graph.

  • weights (array) – An array of the distances of each edge in the graph.

data2graph(index1, index2, weights, num_nodes)

Returns the sparse matrix of a graph given the indices and data.

Parameters:
  • index1 (array) – Index of one of the nodes in the edges of the graph.

  • index2 (array) – Index of one of the nodes in the edges of the graph.

  • weights (array) – An array of the weights of each edge in the graph.

  • num_nodes (int) – Number of nodes.

Returns:

graph (csr_matrix) – A sparse matrix of the edges in a graph and corresponding node indexes.