本文整理汇总了Python中Matrix.Matrix.transpose方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.transpose方法的具体用法?Python Matrix.transpose怎么用?Python Matrix.transpose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.transpose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: power
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import transpose [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
示例2: set_covariance
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import transpose [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))
示例3: lanczos
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import transpose [as 别名]
def lanczos(A):
k = len(A)
b = Vector.rand(n=k)
q = [Vector.new(n=k) for i in range(2)]
q[1] = b / abs(b)
b = [0]
a = [0]
for i in range(1, int(2 * sqrt(k))):
z = Vector((A * q[i]).transpose()[0])
a.append(float(Matrix([q[i]]) * z))
z = z - q[i] * a[i] - q[i-1] * b[i-1]
for j in q:
z -= j * (z * j)
for j in q:
z -= j * (z * j)
b.append(abs(z))
if b[i] == 0:
break
q.append(z / b[i])
Q = Matrix(q[-k-1:-1]).transpose()
T = Q.transpose() * A * Q
return (Q, T, )
示例4: buildLocal_S
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import transpose [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
示例5: buildGlobal_S
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import transpose [as 别名]
#.........这里部分代码省略.........
#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)
#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
S_g = (C.transpose().multiply(S_g)).multiply(C)