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


Python Matrix.set方法代码示例

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


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

示例1: get_matrix

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import set [as 别名]
 def get_matrix(self):
     rows, cols = self.get_size()
     matrix     = Matrix(rows, cols)
     for child in self.get_children():
         box = self.find_box_child(child)
         matrix.set(child, box.left, box.top, box.right, box.bottom)
     return matrix
开发者ID:gisce,项目名称:erpclient,代码行数:9,代码来源:CanvasTable.py

示例2: reduced

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import set [as 别名]
def reduced():
	global S_ff
	global S_fp
	
	S_ff = Matrix(i=(U_f.rows),j=(U_f.rows))
	S_fp = Matrix(i=(U_f.rows),j=(U_p.rows))
	for i in range(1,S_ff.rows+1):
		for j in range(1,S_g.columns+1):
			if (j <= U_f.rows):
				S_ff.set(i,j,S_g.get(i,j))
			else:
				S_fp.set(i,j-U_f.rows,-1*S_g.get(i,j))
开发者ID:AkeelAli,项目名称:Numerical,代码行数:14,代码来源:MeshSolver.py

示例3: buildGlobal_S

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import set [as 别名]
def buildGlobal_S(nodeH, triangleL, pList):
	global S_g
	global U_f
	global U_p
	global U_con_order
	#populate global S with zeroes
	S_g = Matrix(i=(len(triangleL)*3),j=(len(triangleL)*3))
	for i in range(1,S_g.rows+1):
		for j in range(1,S_g.columns+1):
			S_g.set(i,j,0)
	
	#build local S for each triangle and place it in global S
	i = 1 #index where we'll be placing the local S into global S
	j = 1
	for k in range(0,len(triangleL)):
		S_l = buildLocal_S(triangleL[k])
		#add it to S_g in appropriate place
		for a in range(1,S_l.rows+1):
			for b in range(1, S_l.columns+1):
				S_g.set(i,j,S_l.get(a,b))
				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)
	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) 
	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)
	#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)
	
#.........这里部分代码省略.........
开发者ID:AkeelAli,项目名称:Numerical,代码行数:103,代码来源:MeshSolver.py

示例4: Choleski

# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import set [as 别名]
def Choleski(A,b,halfBandwidth=None):
	#if no halfBandwidth is provided, then it equals columns=rows
	if (halfBandwidth is None):
		halfBandwidth=A.columns
		
	originalA=copy.deepcopy(A)
	originalb=copy.deepcopy(b)
	
	n=A.rows
	
	#checks to see that A is square, and b matches A
	assert n==A.columns
	assert n==b.rows
	
	#TODO checks to see if A is symmetric?
	
	startTime=clock()
	
	#ELIMINATION
	for j in range(1,n+1):
		if (A.get(j,j)<=0): 
			print "Choleski Error: Passed A is not real, symmetric or positive definite"
			return -1
		
		A.set(j,j,math.sqrt(A.get(j,j)))
		b.set(j,1,b.get(j,1)/A.get(j,j))

		#added this to set the upper part of A (L) to 0 [optional in the algorithm]
		for i in range(1,j):
			A.set(i,j,0)
		
		for i in range(j+1,halfBandwidth+1):
			A.set(i,j,A.get(i,j)/A.get(j,j))
			b.set(i,1,b.get(i,1)-(A.get(i,j)*b.get(j,1)))
			
			for k in range(j+1,i+1):
				A.set(i,k,A.get(i,k)-(A.get(i,j)*A.get(k,j)))
				
	#BACK SUBSTITUTION
	x=Matrix(i=n,j=1) #create empty matrix of specified dimensions
	
	#counting backwards starting from n
	for i in range(n,0,-1):
		#compute the summation
		sum=0
		for j in range(i+1,halfBandwidth+1):
			sum+=A.get(j,i)*x.get(j,1)
		
		x.set(i,1,(b.get(i,1)-sum)/A.get(i,i))
	
	elapsedTime=clock()-startTime
	
	# print "=============================================="
	# print "START Choleski Function Output						"
	# print "=============================================="
	# print ""
	# print "Given:"
	# print "-------------------------"
	# print "A ="
	# print originalA
	# print "b ="
	# print originalb
	# print ""
	# print "-------------------------"
	# print "Solution"
	# print "-------------------------"
	# print "x ="
	# print x
	# print "=============================================="
	# print "END Choleski Function Output						"
	# print "=============================================="
	print ""
	
	return x
开发者ID:AkeelAli,项目名称:Numerical,代码行数:76,代码来源:Choleski.py


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