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


Python Matrix.insert方法代码示例

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


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

示例1: 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:colossus-technologies,项目名称:copads,代码行数:28,代码来源:graph.py

示例2: 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:colossus-technologies,项目名称:copads,代码行数:27,代码来源:graph.py

示例3: otherGaussSiedelB

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import insert [as 别名]
def otherGaussSiedelB(A,m):
    toReturn = Matrix(m,m)
    for i in range(0,m):
        for j in range(0,m):
            if i == j:
                toReturn.insert(i,j,(1-A.at(i,j)))
            else:
                toReturn.insert(i,j,(-A.at(i,j)))
    return copy.deepcopy(toReturn)
开发者ID:mayk93,项目名称:College,代码行数:11,代码来源:homeWork3v4.py

示例4: rotationMethod

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import insert [as 别名]
def rotationMethod(m,A,a,epsilon,p):
    #print("Start Rotation.")
    VECTOR = 1
    X = Matrix(m,VECTOR)
    oldA = Matrix(m,m)
    r = Matrix(m,VECTOR)
    iterationNumber = 0
    condition = True
    #print("Entering while.")
    while condition:
        #print("OldA copy.")
        oldA = copy.deepcopy(A)
        #print("0")
        r = copy.deepcopy(a.substractMatrix(A.matrixMultiplication(X,a)))
        #print("1")
        (xpq,p,q) = getMax(A.lowerTriangularMatrix())
        #print("2")
        theta = 0
        if A.lowerTriangularMatrix().at(p,p) == A.lowerTriangularMatrix().at(q,q):
            #print("3")
            theta = math.pi/4
        else:
            #print("4")
            theta = ( 2 * xpq )/(A.upperTriangularMatrix().at(p,p) - A.upperTriangularMatrix().at(q,q) + (10**(-5)))
        #print("Determined theta.")
        c = math.cos(theta)
        s = math.sin(theta)
        #print("5")
        T = Matrix(m,m)
        for i in range(0,T.numberOfColumns):
            T.insert(i,i,1)
        T.insert(p,p,c)
        T.insert(p,q,s)
        T.insert(q,p,-s)
        T.insert(q,q,c)
        #print("Determined T.")
        A = copy.deepcopy((T.transpose()).multiplyMatrix(oldA.multiplyMatrix(T)))
        #condition = not r.isAlmostZero()
        if iterationNumber%100 == 0:
            print("-----")
            print("Situation at iteration:",iterationNumber)
            print("Condition:",condition)
            print("A matrix:")
            A.display()
            print("X matrix:")
            X.display()
            print("-----")
        X = copy.deepcopy(oldA)
        iterationNumber += 1
        condition = iterationNumber > 10**(15)
        #condition = checkX(X)

    print("===== Rotation Method =====")
    print("X:")
    X.display()
    print("A:")
    A.display()
    #print("Test:")
    #r.display()
    print("====================")
开发者ID:mayk93,项目名称:College,代码行数:62,代码来源:homeWork3v3.py

示例5: rotationMethod

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import insert [as 别名]
def rotationMethod(m,A,a,epsilon,p):
    VECTOR = 1
    X = Matrix(m,VECTOR)
    oldA = Matrix(m,m)
    r = Matrix(m,VECTOR)
    iterationNumber = 0
    condition = True
    while condition:
        oldA = copy.deepcopy(A)
        r = copy.deepcopy(a.substractMatrix(A.matrixMultiplication(X,a)))
        (xpq,p,q) = getMax(A.lowerTriangularMatrix())
        theta = 0
        if A.lowerTriangularMatrix().at(p,p) == A.lowerTriangularMatrix().at(q,q):
            theta = math.pi/4
        else:
            theta = (1/2)*math.arct(( 2 * xpq )/(A.upperTriangularMatrix().at(p,p) - A.upperTriangularMatrix().at(q,q)))
        c = math.cos(theta)
        s = math.sin(theta)
        T = Matrix(m,m)
        for i in range(0,T.numberOfColumns):
            T.insert(i,i,1)
        T.insert(p,p,c)
        T.insert(p,q,s)
        T.insert(q,p,-s)
        T.insert(q,q,c)
        A = copy.deepcopy((T.transpose()).multiplyMatrix(oldA.multiplyMatrix(T)))
        '''
        if iterationNumber%100 == 0:
            print("-----")
            print("Situation at iteration:",iterationNumber)
            print("Condition:",condition)
            print("A matrix:")
            A.display()
            print("X matrix:")
            X.display()
            print("-----")
        '''
        X = copy.deepcopy(oldA)
        iterationNumber += 1
        condition = (iterationNumber < ITERATIONS)

    print("===== Rotation Method =====")
    print("X:")
    X.display()
    print("A:")
    A.display()
    print("Test:")
    r.display()
    print("====================")
开发者ID:mayk93,项目名称:College,代码行数:51,代码来源:homeWork3v4.py


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