Skip to main content

Graph.to_adj_matrix

Generate an adjacency matrix from the graph

Usage

to_adj_matrix()

Returns:
      tuple
            Tuple where the first element is the mapping of vertice number to zero based indexing. Second element is the adjacency matrix.

Example

from jellybeans.structures import Graphg = Graph()g.add_vertex(1)g.add_vertex(5)g.add_vertex(9)g.add_bidirected_edge(1, 5, (20, 30))g.add_edge(5, 9, 12)print(g.to_adj_matrix()) # ({1: 0, 5: 1, 9: 2}, [[0, 20, 0], [30, 0, 12], [0, 0, 0]])