【发布时间】:2019-07-05 22:57:18
【问题描述】:
我正在使用 numpy 处理图像卷积代码:
def CG(A, b, x, imax=10, epsilon = 0.01):
steps=np.asarray(x)
i = 0
r = b - A * x
d = r.copy()
delta_new = r.T * r
delta_0 = delta_new
while i < imax and delta_new > epsilon**2 * delta_0:
q = A * d
alpha = float(delta_new / (d.T * q))
x = x + alpha * d
if i%50 == 0:
r = b - A * x
else:
r = r - alpha * q
delta_old = delta_new
delta_new = r.T * r
beta = float(delta_new / delta_old)
d = r + beta * d
i = i + 1
steps = np.append(steps, np.asarray(x), axis=1)
return steps
我收到以下错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
在线while i < imax and delta_new > epsilon**2 * delta_0:
谁能告诉我我做错了什么?
【问题讨论】:
-
欢迎来到 Stackoverflow!为了充分利用该站点,ask good questions 很重要,其中包括创建一个 Minimal, Complete, and Verifiable 示例。
标签: python python-3.x numpy