def mesh_degree_matrix(mesh, rtype='array'): """Creates a vertex degree matrix from a Mesh datastructure. Parameters ---------- mesh : :class:`compas.datastructures.Mesh` Instance of mesh. rtype : Literal['array', 'csc', 'csr', 'coo', 'list'], optional Format of the result. Returns ------- array_like Constructed vertex degree matrix. Examples -------- >>> from compas.datastructures import Mesh >>> mesh = Mesh.from_polyhedron(6) >>> D = mesh_degree_matrix(mesh) >>> type(D) <class 'numpy.ndarray'> >>> D = mesh_degree_matrix(mesh, rtype='csr') >>> D = mesh_degree_matrix(mesh) >>> D.diagonal() array([3., 3., 3., 3., 3., 3., 3., 3.]) """ key_index = mesh.key_index() adjacency = [[key_index[nbr] for nbr in mesh.vertex_neighbors(key)] for key in mesh.vertices()] return degree_matrix(adjacency, rtype=rtype)
def mesh_degree_matrix(mesh, rtype='array'): """Creates a vertex degree matrix from a Mesh datastructure. Parameters ---------- mesh : compas.datastructures.Mesh Instance of mesh. rtype : {'array', 'csc', 'csr', 'coo', 'list'} Format of the result. Returns ------- array-like Constructed vertex degree matrix. Examples -------- >>> D = mesh_degree_matrix(mesh) >>> type(D) <class 'numpy.ndarray'> >>> D = mesh_degree_matrix(mesh, rtype='csr') >>> type(D) <class 'scipy.sparse.csr.csr_matrix'> >>> D = mesh_degree_matrix(mesh) >>> D.diagonal() array([2., 3., 3., 3., 3., 2., 3., 4., 4., 4., 4., 3., 3., 4., 4., 4., 4., 3., 3., 4., 4., 4., 4., 3., 3., 4., 4., 4., 4., 3., 2., 3., 3., 3., 3., 2.]) """ key_index = mesh.key_index() adjacency = [[key_index[nbr] for nbr in mesh.vertex_neighbors(key)] for key in mesh.vertices()] return degree_matrix(adjacency, rtype=rtype)
def mesh_degree_matrix(mesh, rtype='array'): """Creates a vertex degree matrix from a Mesh datastructure. Parameters ---------- mesh : obj Mesh datastructure object to get data from. rtype : {'array', 'csc', 'csr', 'coo', 'list'} Format of the result. Returns ------- array-like Constructed vertex degree matrix. """ key_index = mesh.key_index() adjacency = [[key_index[nbr] for nbr in mesh.vertex_neighbors(key)] for key in mesh.vertices()] return degree_matrix(adjacency, rtype=rtype)
def network_degree_matrix(network, rtype='array'): """Creates a node degree matrix from a Network datastructure. Parameters ---------- network : obj Network datastructure object to get data from. rtype : Literal['array', 'csc', 'csr', 'coo', 'list'], optional Format of the result. Returns ------- array_like Constructed node degree matrix. """ key_index = network.key_index() adjacency = [[key_index[nbr] for nbr in network.neighbors(key)] for key in network.nodes()] return degree_matrix(adjacency, rtype=rtype)
def D(self): return degree_matrix(self.adjacency, 'csr')