3
import numpy as np
from numpy.linalg import solve,norm,cond,inv,pinv
import math
import matplotlib.pyplot as plt
from scipy.linalg import toeplitz
from numpy.random import rand
c = np.zeros(512)
c[0] = 2
c[1] = -1
a = c
A = toeplitz(c,a)
cond_A = cond(A,2)
# creating 10 random vectors 512 x 1
b = rand(10,512)
# making b into unit vector
for i in range (10):
b[i]= b[i]/norm(b[i],2)
# creating 10 random del_b vectors
del_b = [rand(10,512), rand(10,512), rand(10,512), rand(10,512), rand(10,512), rand(10,512), rand(10,512), rand(10,512), rand(10,512), rand(10,512)]
# del_b = 10 sets of 10 vectors (512x1) whose norm is 0.01,0.02 ~0.1
for i in range(10):
for j in range(10):
del_b[i][j] = del_b[i][j]/(norm(del_b[i][j],2)/((float(j+1)/100)))
x_in = [np.zeros(512), np.zeros(512), np.zeros(512), np.zeros(512), np.zeros(512), np.zeros(512), np.zeros(512), np.zeros(512), np.zeros(512), np.zeros(512)]
x2 = np.zeros((10,10,512))
for i in range(10):
x_in[i] = A.transpose()*b[i]
for i in range(10):
for j in range(10):
x2[i][j] = ((A.transpose()*(b[i]+del_b[i][j]))
最后一行给我错误。 (输出操作数需要减少,但是减少未启用) 我该如何解决它? 我是新来的蟒蛇并请让我知道,如果没有做到这一点输出操作数需要减少,但是减少未启用Python
由于更简单的方法
将有助于大大如果你可以添加import语句(如numpy的NP,SciPy的#小号托普利茨,等等),这样的代码复制,粘贴和运行原样。 – YXD 2013-02-21 10:26:35
我刚刚包括在内。谢谢 – kiki 2013-02-21 17:11:48
在提高错误的行中,左手边的形状是'(512,)',右手边的形状是(512,512)'。您试图将一个512x512二维数组塞入一个512长的一维数组中。 – DSM 2013-02-21 17:22:17