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


Python matrix.Matrix类代码示例

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


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

示例1: test_should_multiply_itself_by_1x1_matrix

    def test_should_multiply_itself_by_1x1_matrix(self):
        matrix = Matrix(1, 1, 2)
        other_matrix = Matrix(1, 1, 1337)

        matrix.multiply(other_matrix)

        self.assertEquals(2 * 1337, matrix.get_item(0, 0))
开发者ID:robinrob,项目名称:flask-hello,代码行数:7,代码来源:test_matrix.py

示例2: test_should_substract_other_10x10_matrix

    def test_should_substract_other_10x10_matrix(self):
        matrix = Matrix(10, 10, 1338)
        other_matrix = Matrix(10, 10, 1)

        matrix.subtract(other_matrix)

        self.assertEquals(1337, matrix.get_item(9, 9))
开发者ID:robinrob,项目名称:flask-hello,代码行数:7,代码来源:test_matrix.py

示例3: test_should_substract_other_1x1_matrix

    def test_should_substract_other_1x1_matrix(self):
        matrix = Matrix(1, 1, 1338)
        other_matrix = Matrix(1, 1, 1)

        matrix.subtract(other_matrix)

        self.assertEquals(1337, matrix.get_item(0, 0))
开发者ID:robinrob,项目名称:flask-hello,代码行数:7,代码来源:test_matrix.py

示例4: test_should_add_itself_to_other_10x10_matrix

    def test_should_add_itself_to_other_10x10_matrix(self):
        matrix = Matrix(10, 10, 1)
        other_matrix = Matrix(10, 10, 1336)

        matrix.add(other_matrix)

        self.assertEquals(1337, matrix.get_item(9, 9))
开发者ID:robinrob,项目名称:flask-hello,代码行数:7,代码来源:test_matrix.py

示例5: test_should_multiply_itself_by_10x10_matrix

    def test_should_multiply_itself_by_10x10_matrix(self):
        matrix = Matrix(10, 10, 2)
        other_matrix = Matrix(10, 10, 1337)

        matrix.multiply(other_matrix)

        self.assertEquals(2 * 1337, matrix.get_item(9, 9))
开发者ID:robinrob,项目名称:flask-hello,代码行数:7,代码来源:test_matrix.py

示例6: makeGraphFromEdges1

 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,代码行数:26,代码来源:graph.py

示例7: test_iter_over_one_row

 def test_iter_over_one_row(self):
     m = Matrix(3, 3)
     m[1][0] = 1
     m[1][1] = 2
     m[1][2] = 3
     self.assertEqual([x for x in m.row(1)], [1, 2, 3])
     self.assertEqual([x for x in m[1]], [1, 2, 3])
开发者ID:plilja,项目名称:project-euler,代码行数:7,代码来源:test_matrix.py

示例8: train

 def train(self, vector):
     matrix_2 = Matrix(vector)
     matrix_1 = Matrix(matrix_2.transpose())
     matrix_3 = matrix_2 * matrix_1
     identity = Matrix.identity(len(vector))
     matrix_4 = matrix_3 - identity
     self.weight = self.weight + matrix_4
开发者ID:EduardRakov,项目名称:hopfieldNetwork,代码行数:7,代码来源:hopfield_network.py

示例9: main

def main():
    r = 66
    c = 66
    s = 7
    test = Matrix(rows=r, columns=c, side=s)
    test.random_matrix()
    test.run()
开发者ID:johann2357,项目名称:conways-game-of-life,代码行数:7,代码来源:main.py

示例10: test_should_add_itself_to_other_1x1_matrix

    def test_should_add_itself_to_other_1x1_matrix(self):
        matrix = Matrix(1, 1, 1)
        other_matrix = Matrix(1, 1, 1336)

        matrix.add(other_matrix)

        self.assertEquals(1337, matrix.get_item(0, 0))
开发者ID:robinrob,项目名称:flask-hello,代码行数:7,代码来源:test_matrix.py

示例11: parse_Matrix

def parse_Matrix(testset):
    print "Parsing text file "+ testset + " into Matrix instance"

    f=open(testset, "r")
    mat_list = [] # this will be returned 
    res = [] # contains list of list that will be changed to a matrix
    res_len = -1
    for line in f.readlines():
	if line.startswith("test"):
	    res.append([])
	    res_len += 1
	else:
	    res[res_len].append(line.rstrip(" \r\n").split(" "))
    
    for elem in res: 
	if(type(elem) == int):
	    mat = Matrix(1,1)
	    mat.matrix = elem
	    mat_list.append(mat)
	else:
            print elem
	    mat = Matrix(len(elem), len(elem[0])) # Matrix(2,10)
	    for r in range(mat.row): # 2
		for c in range(mat.col): # 10
                    mat.matrix[r][c] = int(elem[r][c])
	    mat_list.append(mat)

    return mat_list
开发者ID:bbatta38,项目名称:pydal,代码行数:28,代码来源:matrix_functions.py

示例12: main

def main():
	if len(argv) < 4:
		print "Usage: <num eigenvectors> <tolerance> <text file>"
		return
	data = load_matrix(argv[3])
	k = int(argv[1])
	epsilon = float(argv[2])
	rows = len(data)
	cols = len(data[0])
	A = Matrix(rows, cols, data)
	res, vals = power_method(k, epsilon, A)

	Vecs = Matrix(rows, k)
	for i in range(rows):
		for j in range(k):
			Vecs.data[i][j] = res[j].data[i][0]

	f1 = open('vecs.txt','w')
	f2 = open('vals.txt','w')

	# TODO fix formatting
	for i in range(rows):
		for j in range(k):
			f1.write(str(Vecs.data[i][j]) + ' ')
		f1.write('\n')

	for i in range(k):
		f2.write(str(vals[i]) + '\n')

	f1.close()
	f2.close()
开发者ID:jsachs,项目名称:uchi_ai,代码行数:31,代码来源:eigP.py

示例13: compute

 def compute(self):
     filename = self.getInputFromPort("filename")
     f = open(filename.name, 'r')
     
     # read metadata
     _type = f.readline()
     rows = int(f.readline().strip())
     cols = int(f.readline().strip())
     
     # read attributes
     attributes = f.readline().split(';')
     
     # read id, values and class
     values = np.zeros((rows, cols))
     ids    = []
     labels = []
     for r in range(rows):
         line = f.readline().split(';')
         ids.append(r)
         labels.append(line[0])
         values[r,] = np.array([float(val) for val in line[1:-1]])
         #klass = float(line[-1])
 
     matrix = Matrix()
     matrix.values     = values
     matrix.ids        = ids
     matrix.labels     = labels
     matrix.attributes = attributes
     
     self.setResult('matrix', matrix)
开发者ID:imclab,项目名称:vistrails,代码行数:30,代码来源:config_reader.py

示例14: makeGraphFromEdges2

 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,代码行数:25,代码来源:graph.py

示例15: setUp

    def setUp(self):
        self.ecm = [[1, 1],[1, 0]]
        self.ec = Matrix(["Bearing", "Belt"], ["Import Mechanical", "Export Mechanical"]
                         , lol_to_dict(self.ecm))

        self.cfm = [[0,3],[1,0]]
        self.cf = Matrix(["Creep", "Fatigue"], ["Bearing", "Belt"], lol_to_dict(self.cfm))

        self.cfpm = [[1,2],[5,0]]
        self.cfp = Matrix(["Creep", "Fatigue"], ["Bearing", "Belt"], lol_to_dict(self.cfpm))

        self.efm = [[1,3],[0,3]]
        self.ef = Matrix(["Creep", "Fatigue"], ["Import Mechanical", "Export Mechanical"],
                         lol_to_dict(self.efm))

        self.l1m = [[2,5],[0,5]]
        self.l1 = Matrix(["Creep", "Fatigue"], ["Import Mechanical", "Export Mechanical"],
                          lol_to_dict(self.l1m))

        self.l2m = [[1,1],[0,1]]
        self.l2 = Matrix(["Creep", "Fatigue"], ["Import Mechanical", "Export Mechanical"],
                          lol_to_dict(self.l2m))

        self.c1m = [[5,2],[1,2]]
        self.c1 = Matrix(["Creep", "Fatigue"], ["Import Mechanical", "Export Mechanical"],
                          lol_to_dict(self.c1m))

        self.c2m = [[3,2],[1,2]]
        self.c2 = Matrix(["Creep", "Fatigue"], ["Import Mechanical", "Export Mechanical"],
                          lol_to_dict(self.c2m))
开发者ID:joshbohde,项目名称:red_app,代码行数:30,代码来源:tests.py


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