Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
 def D(self):
     return degree_matrix(self.adjacency, 'csr')