本文整理汇总了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)
示例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)