本文整理汇总了Python中matrix.Matrix.data[i][j]方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.data[i][j]方法的具体用法?Python Matrix.data[i][j]怎么用?Python Matrix.data[i][j]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.data[i][j]方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import data[i][j] [as 别名]
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()
示例2: svd
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import data[i][j] [as 别名]
def svd(k, epsilon, matrix):
# Get the matrix U
W = matrix * matrix.transpose()
U_vecs, U_vals = power_method(k, epsilon, W)
U = Matrix(W.rows, k)
for i in range(U.rows):
for j in range(U.cols):
U.data[i][j] = U_vecs[j].data[i][0]
# Get the matrix V
W = matrix.transpose() * matrix
V_vecs, V_vals = power_method(k, epsilon, W)
V = Matrix(W.rows, k)
for i in range(V.rows):
for j in range(V.cols):
V.data[i][j] = V_vecs[j].data[i][0]
# Get the values for S
S_vals = [sqrt(abs(V_vals[i])) for i in range(k)]
# Format and return the results
return U, S_vals, V
示例3: rand_mat_30
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import data[i][j] [as 别名]
def rand_mat_30():
"""Returns a 30x30 random matrix"""
A = Matrix(30, 30)
left = rand_unit_vec()
right = rand_unit_vec()
for i in range(30):
A.data[i][0] = left[i]
for i in range(30):
A.data[i][29] = right[i]
for i in range(30):
for j in range(1,29):
A.data[i][j] = uniform(0.0,1.0)
return A
示例4: frob_norm
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import data[i][j] [as 别名]
def frob_norm(A, U, S_vals, V):
S = Matrix(len(S_vals), len(S_vals))
for i in range(S.rows):
for j in range(S.cols):
if i == j:
S.data[i][j] = S_vals[i]
Vt = V.transpose()
Recon = U * S * Vt
total = 0
for i in range(A.rows):
for j in range(A.cols):
total += (A.data[i][j] - Recon.data[i][j]) ** 2
ret = sqrt(total)
return ret