Ejemplo n.º 1
0
def mesh_adjacency_matrix(mesh, rtype='array'):
    """Creates a vertex adjacency 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 adjacency matrix.

    Examples
    --------
    >>> from compas.datastructures import Mesh
    >>> mesh = Mesh.from_polyhedron(6)
    >>> A = mesh_adjacency_matrix(mesh)
    >>> type(A)
    <class 'numpy.ndarray'>

    >>> A = mesh_adjacency_matrix(mesh, rtype='csr')

    """
    key_index = mesh.key_index()
    adjacency = [[key_index[nbr] for nbr in mesh.vertex_neighbors(key)] for key in mesh.vertices()]
    return adjacency_matrix(adjacency, rtype=rtype)
Ejemplo n.º 2
0
def mesh_adjacency_matrix(mesh, rtype='array'):
    """Creates a vertex adjacency 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 adjacency matrix.

    Examples
    --------
    >>> A = mesh_adjacency_matrix(mesh)
    >>> type(A)
    <class 'numpy.ndarray'>

    >>> A = mesh_adjacency_matrix(mesh, rtype='csr')
    >>> type(A)
    <class 'scipy.sparse.csr.csr_matrix'>

    """
    key_index = mesh.key_index()
    adjacency = [[key_index[nbr] for nbr in mesh.vertex_neighbors(key)]
                 for key in mesh.vertices()]
    return adjacency_matrix(adjacency, rtype=rtype)
Ejemplo n.º 3
0
def mesh_adjacency_matrix(mesh, rtype='array'):
    """Creates a vertex adjacency 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 adjacency matrix.

    """
    key_index = mesh.key_index()
    adjacency = [[key_index[nbr] for nbr in mesh.vertex_neighbors(key)] for key in mesh.vertices()]
    return adjacency_matrix(adjacency, rtype=rtype)
Ejemplo n.º 4
0
def network_adjacency_matrix(network, rtype='array'):
    """Creates a node adjacency 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 adjacency matrix.

    """
    key_index = network.key_index()
    adjacency = [[key_index[nbr] for nbr in network.neighbors(key)] for key in network.nodes()]
    return adjacency_matrix(adjacency, rtype=rtype)
Ejemplo n.º 5
0
 def A(self):
     return adjacency_matrix(self.adjacency, 'csr')