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 문 (등 NP, scipy #의 토플 리츠 등 NumPy와)을 추가 할 수 있다면 큰 도움이 될 코드를 복사, 붙여 넣기 및 실행 그대로. – YXD
방금 포함되었습니다. 감사합니다 – kiki
오류가 발생하는 행에서 왼쪽은 모양이 (512,)이고 오른쪽이 모양이 (512, 512)입니다. 512x512 2D 배열을 512 길이 1D 배열로 밀어 넣으려고합니다. – DSM