当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.insert方法代码示例

本文整理汇总了Python中Matrix.Matrix.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.insert方法的具体用法?Python Matrix.insert怎么用?Python Matrix.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix.Matrix的用法示例。


在下文中一共展示了Matrix.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makeGraphFromEdges2

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import insert [as 别名]
 def makeGraphFromEdges2(self, edges):
     """
     Constructs an un-directional graph from edges (a list of tuple).
     Each tuple contains 2 vertices.
     An un-directional graph is implemented as a directional graph where
     each edges runs both directions.
     
     @param edges: list of edges
     @type edges: list of 2-element tuples"""
     if type(edges) != list: raise GraphParameterError('Edges must be a \
                             list of tuples')
     from Set import Set
     from Matrix import Matrix
     vertices = list(Set([x[0] for x in edges] + [x[1] for x in edges]))
     adj = Matrix(len(vertices))
     adj = adj.m
     for e in edges:
         row = vertices.index(e[0])
         col = vertices.index(e[1])
         # fill values into lower triangular matrix
         adj[row][col] = adj[row][col] + 1
         # repeat on the upper triangular matrix for undirectional graph
         adj[col][row] = adj[col][row] + 1
     adj.insert(0, vertices)
     self.makeGraphFromAdjacency(adj)
开发者ID:mauriceling,项目名称:cynote2,代码行数:27,代码来源:Graph.py

示例2: makeGraphFromEdges1

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import insert [as 别名]
    def makeGraphFromEdges1(self, edges):
        """
        Constructs a directional graph from edges (a list of tuple).
        Each tuple contains 2 vertices.
        For example, P -> Q is written as ('P', 'Q').

        @param edges: edges
        @type edges: list of 2-element tuple

        @status: Tested method
        @since: version 0.1
        """
        if type(edges) != list: raise GraphParameterError('Edges must be a \
                                list of tuples')
        from Set import Set
        from Matrix import Matrix
        vertices = list(Set([x[0] for x in edges] + [x[1] for x in edges]))
        adj = Matrix(len(vertices))
        adj = adj.m
        for e in edges:
            row = vertices.index(e[0])
            col = vertices.index(e[1])
            # fill values into lower triangular matrix
            adj[row][col] = adj[row][col] + 1
        adj.insert(0, vertices)
        self.makeGraphFromAdjacency(adj)
开发者ID:bfgoh,项目名称:copads,代码行数:28,代码来源:graph.py


注:本文中的Matrix.Matrix.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。