MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / to_matrix

Method to_matrix

numpy_ml/utils/graphs.py:90–96  ·  view source on GitHub ↗

Return an adjacency matrix representation of the graph

(self)

Source from the content-addressed store, hash-verified

88 return [self._V2I[e.to] for e in self._G[v_i]]
89
90 def to_matrix(self):
91 """Return an adjacency matrix representation of the graph"""
92 adj_mat = np.zeros((len(self._V), len(self._V)))
93 for e in self.edges:
94 fr, to = self._V2I[e.fr], self._V2I[e.to]
95 adj_mat[fr, to] = 1 if e.weight is None else e.weight
96 return adj_mat
97
98 def to_adj_dict(self):
99 """Return an adjacency dictionary representation of the graph"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected