connectivity_matrix

compas.numerical.connectivity_matrix(edges, rtype='array')[source]

Creates a connectivity matrix from a list of vertex index pairs.

Parameters:
edgeslist

List of lists [[node_i, node_j], [node_k, node_l]].

rtype{‘array’, ‘csc’, ‘csr’, ‘coo’, ‘list’}

Format of the result.

Returns:
array-like

Constructed connectivity matrix.

Notes

The connectivity matrix encodes how edges in a network are connected together. Each row represents an edge and has 1 and -1 inserted into the columns for the start and end nodes.

\[\mathbf{C}_{ij} = \cases{ -1 & if edge i starts at vertex j \cr +1 & if edge i ends at vertex j \cr 0 & otherwise }\]

A connectivity matrix is generally sparse and will perform superior in numerical calculations as a sparse matrix.

Examples

>>> connectivity_matrix([[0, 1], [0, 2], [0, 3]], rtype='array')
array([[-1.,  1.,  0.,  0.],
       [-1.,  0.,  1.,  0.],
       [-1.,  0.,  0.,  1.]])