Convert graph to matrix form
These methods convert a graph to a matrix representation .
- class PGraph.PGraph(arg=None, metric=None, heuristic=None, verbose=False)[source]
- Laplacian()[source]
Laplacian matrix for the graph
- Returns:
Laplacian matrix
- Return type:
NumPy ndarray
g.Laplacian()
is the Laplacian matrix (NxN) of the graph where N is the number of vertices.Note
Laplacian is always positive-semidefinite.
Laplacian has at least one zero eigenvalue.
- The number of zero-valued eigenvalues is the number of connected
components in the graph.
- Seealso:
- adjacency()[source]
Adjacency matrix of graph
- Returns:
adjacency matrix
- Return type:
ndarray(N,N)
The elements of the adjacency matrix
[i,j]
are 1 if vertexi
is connected to vertexj
, else 0.Note
vertices are numbered in their order of creation. A vertex index can be resolved to a vertex reference by
graph[i]
.for an undirected graph the matrix is symmetric
Eigenvalues of
A
are real and are known as the spectrum of the graph.The element
A[i,j]
can be considered the number of walks of length one edge from vertexi
to vertexj
(either zero or one).If
Ak = A ** k
the elementAk[i,j]
is the number of walks of lengthk
from vertexi
to vertexj
.
- Seealso:
- degree()[source]
Degree matrix of graph
- Returns:
degree matrix
- Return type:
ndarray(N,N)
This is a diagonal matrix where element
[i,i]
is the number of edges connected to vertex idi
.- Seealso:
adjacency()
incidence()
laplacian()
- distance()[source]
Distance matrix of graph
- Returns:
distance matrix
- Return type:
ndarray(n,n)
The elements of the distance matrix
D[i,j]
is the edge cost of moving from vertexi
to vertexj
. It is zero if the vertices are not connected.
- incidence()[source]
Incidence matrix of graph
- Returns:
incidence matrix
- Return type:
ndarray(n,ne)
The elements of the incidence matrix
I[i,j]
are 1 if vertexi
is connected to edgej
, else 0.Note
vertices are numbered in their order of creation. A vertex index can be resolved to a vertex reference by
graph[i]
.edges are numbered in the order they appear in
graph.edges()
.
- Seealso: