Skip to content
Advertisement

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

I am working on an Image Convolution code using numpy:

JavaScript

I get the below error:

JavaScript

on line while i < imax and delta_new > epsilon**2 * delta_0:

Could anyone please tell me what am I doing wrong ?

Advertisement

Answer

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:

JavaScript

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.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement