本文整理汇总了Python中matrix.Matrix.zero方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.zero方法的具体用法?Python Matrix.zero怎么用?Python Matrix.zero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.zero方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testZeroMatrix2
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import zero [as 别名]
def testZeroMatrix2(self):
self.assertEquals(
Matrix([0, 0, 0], [0, 0, 0]),
Matrix.zero(2, 3))
示例2: get_mod_addj_matrix
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import zero [as 别名]
# -*- encoding: utf-8 -*-
from matrix import Matrix
from graph import Graph
def get_mod_addj_matrix(graph):
""" Erstellt eine modifizierte Adjazenzmatrix aus einem Graphen
"""
out_deg = [sum(map(lambda(x,y): 1 if v == x else 0, graph.edges)) \
for v in graph.vertices] # bestimme Ausgrad aller Knoten
mod_addj_matrix = Matrix.zero(len(graph.vertices))
# erstelle Nullmatrix
# setze Werte in erstellter Nullmatrix für modifizierte Adjazenzmatrix
for i,v_i in enumerate(graph.vertices):
for j,v_j in enumerate(graph.vertices):
if (v_i,v_j) in graph.edges:
mod_addj_matrix[i][j] = 1.0/out_deg[i]
return mod_addj_matrix
def pagerank(graph, d = 0.25, error = 0.001):
N = len(graph.vertices)
Pi = Matrix([[1.0/N for n in range(N)]])
A1 = get_mod_addj_matrix(graph)
A2 = A1.scalar_mul(1-d) + Matrix.one(A1.height,A1.width).scalar_mul(d/N)
iterations = 1
Pi_new = Pi * A2
while (Pi_new-Pi).max_norm() >= error:
Pi = Pi_new