NumPy Error: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

后端 未结 3 1072
心在旅途
心在旅途 2020-12-04 02:27

I am working on an Image Convolution code using numpy:

def CG(A, b, x, imax=10, epsilon = 0.01):
    steps=np.asarray(x)
    i = 0
    r = b - A * x
    d =          


        
3条回答
  •  眼角桃花
    2020-12-04 03:04

    It looks like delta_new and delta_0 are Numpy arrays, and Numpy doesn't know how to compare them.

    As an example, imagine if you took two random Numpy arrays and tried to compare them:

    >>> a = np.array([1, 3, 5])
    >>> b = np.array([5, 3, 1])
    >>> print(a>> bool(a

    You have to basically "pick" how to collapse the comparisons of all of the values across all of your arrays down to a single bool.

    >>> (a>> (a

提交回复
热议问题