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


Python Matrix.multiply方法代码示例

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


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

示例1: power

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import multiply [as 别名]
    def power(self, iterations, mat, estimate):
        r = 1
        k = 0
        m = iterations
        y = estimate
        x = mat.multiply(y)
        while r > .001 and k < m:
            max_x = x.find_max()
            x.scaler(1 / max_x)
            y = Matrix(x.get_data())
            x = mat.multiply(y)
            temp = Matrix(y.get_data())
            temp.transpose()
            a = temp.multiply(x).get_data()[0][0]
            b = temp.multiply(y).get_data()[0][0]
            mu = a / b
            r = Matrix(y.get_data())
            r.scaler(mu)
            r = r.subtract(x)
            r = r.find_max()
            k += 1

        y.scaler(1 / mu)

        return mu, mat.trace() - mu, y
开发者ID:darryl-papke,项目名称:340-Code,代码行数:27,代码来源:Operations.py

示例2: set_covariance

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import multiply [as 别名]
    def set_covariance(self):
        for i in self.matrices:
            a = i.subtract(self.mean)
            a_transpose = Matrix(a.get_data())
            a_transpose.transpose()
            b = a_transpose.multiply(a)
            self.covariance = self.covariance.add(b)

        self.covariance.scaler(1 / len(self.matrices))
开发者ID:darryl-papke,项目名称:340-Code,代码行数:11,代码来源:Operations.py

示例3: buildLocal_S

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import multiply [as 别名]
def buildLocal_S(triangle):
	area = getArea(triangle)
	
	n1 = triangle.node1
	n2 = triangle.node2
	n3 = triangle.node3
	
	# build X matrix
	X = Matrix([	[1, n1.x, n1.y],
					[1, n2.x, n2.y],
					[1, n3.x, n3.y]
				])

	# compute inverse(X)
	X_inverse = inverse3x3(X)
	
	# compute transpose(X_inverse)
	X_i_t = X_inverse.transpose()
	
	# get delta_alpha (i and j components)
	alphaI = Matrix([  	[X_i_t.get(1,2)],
						[X_i_t.get(2,2)],
						[X_i_t.get(3,2)]
					])				
	alphaJ = Matrix([	[X_i_t.get(1,3)],
						[X_i_t.get(2,3)],
						[X_i_t.get(3,3)]
					])
	
	S = alphaI.multiply(alphaI.transpose()).add(alphaJ.multiply(alphaJ.transpose()))
	
	for i in range(1,3+1):
		for j in range(1,3+1):
			S.set(i,j,S.get(i,j)*(area))
			
	return S
开发者ID:AkeelAli,项目名称:Numerical,代码行数:38,代码来源:MeshSolver.py

示例4: buildGlobal_S

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import multiply [as 别名]

#.........这里部分代码省略.........
				j+=1
			i+=1
			j-=3
		j+=3
	
	#No need for findJoint in the case of our meshes as nodes are already joined	
	#joint = findJointNodes(triangleL)
	
	#build a hash from id(node) -> node
	nodeID = {}
	for i in range(1,len(nodeH)+1):
		nodeID[id(nodeH[i])] = nodeH[i]
	
	#build U disjoint with node ids (rather than voltages)
	print "#build U disjoint with node ids (rather than voltages)"
	U_dis = Matrix(i=(len(triangleL)*3),j=1)
	row = 1
	for k in range(0,len(triangleL)):
		U_dis.set(row,1,id(triangleL[k].node1))
		U_dis.set(row+1,1,id(triangleL[k].node2))
		U_dis.set(row+2,1,id(triangleL[k].node3))
		row+=3
		
	
	#build U conjoint with node ids (and build C along the way)
	print "#build U conjoint with node ids (and build C along the way)"
	C = Matrix(i=U_dis.rows,j=len(nodeH))
	row_C = 1
	U_con = Matrix(i=len(nodeH),j=1)
	row_U_c = 1 #row in conjoint where we place our next element
	for row_d in range(1,U_dis.rows+1):
		node_id = U_dis.get(row_d,1)
		add = True
		#check if it's already in U_con
		for j in range(row_U_c-1,0,-1):
			if (U_con.get(j,1) == node_id):
				add = False
				break
		if (add):
			#add it to U_con since it hasn't been added yet
			U_con.set(row_U_c,1,node_id)
			C.set(row_C,row_U_c,1.0)
			row_U_c+=1			
			row_C+=1
		else:
			C.set(row_C,j,1.0)
			row_C+=1
	
	#rearrange	U_con and C (to put free up, and predefined down)
	print "#rearrange	U_con and C (to put free up, and predefined down)"
	#method used is 2 pointers moving in opposite directions on U_con
	#the pointer moving up looks for a free node, and the pointer moving down looks for predef node
	#swap both, stop process when cross
	down = 1 #index moving down
	up = U_con.rows #index moving up
	while (down < up):
		while (down < up and nodeID[U_con.get(down,1)].number not in pList):
			down+=1
		if (nodeID[U_con.get(down,1)].number not in pList):
			break #nothing more to switch around
			
		while (up > down and nodeID[U_con.get(up,1)].number in pList): #looking for free from bottom
			up-=1
		
		if (nodeID[U_con.get(up,1)].number in pList):
			break #nothing more to switch around
		
		#do the swap for U_con
		tmp = U_con.get(up,1)
		U_con.set(up,1,U_con.get(down,1))
		U_con.set(down,1,tmp)
		
		#do the swap for C (swap columns)
		for i in range(1,C.rows+1):
			tmp = C.get(i,up)
			C.set(i,up,C.get(i,down))
			C.set(i,down,tmp)
	
	#convert U_con to actual voltage values (but keep track of ordering)
	for i in range(1,U_con.rows+1):
		U_con_order.append(nodeID[U_con.get(i,1)].number)
		U_con.set(i,1,nodeID[U_con.get(i,1)].voltage)
	
	#build U_p and U_f
	print "#build U_p and U_f"
	U_f = Matrix(i=down-1,j=1)
	U_p = Matrix(i=U_con.rows-U_f.rows,j=1)
	for i in range(1,U_f.rows+1):
		U_f.set(i,1,U_con.get(i,1))
	for i in range(1,U_p.rows+1):
		U_p.set(i,1,U_con.get(i+down-1,1))
	
	#finally compute S_g
	print "#finally compute S_g"
	print "		#transpose C"
	C_T = C.transpose()
	print "		#multiply C transpose by S_g"
	S_g = (C_T.multiply(S_g))
	print "		#multiply result by C"
	S_g = S_g.multiply(C)
开发者ID:AkeelAli,项目名称:Numerical,代码行数:104,代码来源:MeshSolver.py


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